Home > Django, Linux > Install Django with Postgresql

Install Django with Postgresql

This post will guide you quickly step-by-step installing django and Postgresql on Linux Mint.

  1. Install Postgresql Server
    $ sudo apt-get install postgresql
  2. Switch account to postgres and create db user for django project (create non superuser that can create db)
    $ sudo -i -u postgres
    $ createuser djangouser -P --interactive
  3. Connect to postgresql server as djangouser and create db for django project
    $ psql -u djangouser -h localhost -d postgres -W
    $ create database django_project_db
  4. Create Django Environment and install postgres db adapter for python
    $ mkvirtualenv django-project
    $ pip install django psycopg2
  5. Create Django Project
    $ django-admin startproject mysite
  6. Change django project db settings
    $ cd mysite
    $ nano mysite/settings.py
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'django_project_db',
            'USER': 'djangouser',
            'PASSWORD': 'djangouser',
            'HOST': 'localhost',
            'POST': '5432'
        }
    }
  7. Initialize DB data for django project
    $ python manage.py migrate
  8. Test by running the server
    $ python manage.py runserver 0.0.0.0:8000

     

Advertisements
Categories: Django, Linux
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: