Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PostgreSQL configuration for Django in Ubuntu
- # http://pastebin.com/1kgtjh06
- #
- # This tutorial and code explains how to install and configure PostgreSQL
- # to use with Django framework of Python.
- # There are much more secure and complex methods to do that, but if all you
- # need to do is to starting quickly, you can follow the steps here.
- #
- # The steps here will also avoid you getting
- # "FATAL: Ident authentication failed" errors:
- # https://duckduckgo.com/?q=fatal%3A+ident+authentication+failed
- #
- # By the way, you can apply the steps for PostgreSQL for other applications,
- # you do not have to use Django.
- #
- # In this tutorial, my user name is 'blade'.
- # The lines you need to type are not commented,
- # all my comments and outputs are commented by convention.
- #
- # I have been using Ubuntu 11.04 "Natty Narwhal" for this tutorial, but
- # the steps are applicable to other systems too.
- # I am assuming you have already installed Django.
- # To make sure, type the following in your shell
- # (your shell like bash, not Python shell):
- python -c "import django; print django.VERSION"
- # (1, 2, 5, 'final', 0)
- # First, install the PostgreSQL stuff from your shell:
- sudo apt-get install postgresql python-psycopg2 pgadmin3
- # python-psycopg2 is a PostgreSQL database adapter for the Python.
- # Although pgadmin3 is not a requirement, it is recommended to easily
- # manage your database server.
- # To check if python-psycopg2 is installed correctly, type the following
- # in the shell:
- python -c "import psycopg2; print psycopg2.apilevel"
- # 2.0
- # If the security is not your main problem and want to do things quick with
- # minimum effort, create a PostgreSQL user with your Ubuntu login user name.
- # To do that, type the following in your shell:
- sudo -u postgres createuser --superuser blade
- # [sudo] password for blade:
- # Then, set a password for your user from your shell:
- sudo -u postgres psql
- # After this operation, psql (command line client for PostgreSQL)
- # will be launched.
- # psql (8.4.8)
- # Type "help" for help.
- postgres=# \password blade
- Enter new password:
- Enter it again:
- postgres=# \q
- # Your user is now ready.
- # Then, the easiest way, is to create a database with your username.
- # To do that type the following in your shell:
- sudo -u postgres createdb blade
- # Optionally, you can set a password for postgres user to use in pgadmin3:
- # To set a password for the postgres user, follow the steps you applied before:
- sudo -u postgres psql
- \password postgres
- Enter new password:
- Enter it again:
- postgres=# \q
- # Edit your Django settings file (settings.py) so that it looks like this:
- ....
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': 'blade',
- 'USER': 'blade',
- 'PASSWORD': 'the_password_specified_in_psql_for_blade',
- 'HOST': '',
- 'PORT': '',
- }
- }
- ....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement