Django Apps with PostgreSQL Database

Summarized section in the end of article.

Step 1. Preparation
install virtualenv: pip install virtualenv
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django and pysoppg2 in virtualenv: pip install django psycopg2

Step 2. Create Django Project
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject

Step 3. Set Up Database Connection
By default django provide sqlite database and connections. We need to change it to postgresql. Asumption, postgresql database is ready to be connected.
Update project_folder/settings.py

DATABASES = {'default': 
{'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'database_user',
'PASSWORD': 'database_pass',
'HOST': 'localhost',
'PORT': '5432',
}
}

Step 4. Initial Migrations
Migrate Django: python manage.py migrate
This command will generate some initial tables in postgresql database.

Step 5. Run Server
Run Django: python manage.py runserver

Summarized section
Update project_folder/settings.py

DATABASES = {'default': 
{'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'database_user',
'PASSWORD': 'database_pass',
'HOST': 'localhost',
'PORT': '5432',
}
}

Software Engineer