Connect PostgreSQL with Python and 3.4 Django 1.8

As we already know that PostgreSQL is an object-relational database management system (ORDBMS) .It uses for storing data ,allowing them for retrieval by the other software application securely.
PostgreSQL is a cross-platform and work on almost any operating system.You can Connect PostgreSQL with any Language.For more information on PostgreSQL you can visit there official site

So to Connect PostgreSQL with Python 3.4 and Django 1.8

1.Install PostgreSQL on Linux  / Ubuntu

  • Open you terminal window and login as a root user.
  • Type–> sudo apt-get install python3-dev libpq-dev
  • Then type–> “sudo apt-get install postgresql” OR “sudo aptitude install postgresql postgresql-contrib” as shown in fig without quotes.This will Install PostgreSQL in your system
  • Connect PostgreSQL
  • Then check status of PostgreSQL service type–> “service postgresql status”
  • To start PostgreSQL type–> “sudo service postgresql start” (without double quotes)
  • Then login to PostgreSQL by typing command–> “sudo -i -u postgres” (without double quotes)
  • Now create new user by typing–> “createuser –interactive –pwprompt” (without double quotes)then it will ask you to name of role to add,type whatever you want to call,then type password whatever you want.then it will ask you following this as given in image.fallow as it answer in image where y for Yes n for No
  • Connect PostgreSQL
  • Then create database type–> createdb name of db (whatever you want ex. Createdb people)
  • then type–> psql
  • Then grant Privileges to our newly create user by typing–> grant all privileges on database people to peps
  • Then exit from PostgreSQL by typing–> exit
  • Then to login to specific database to use it type–>“sudo -u postgres psql -d people” (where people is the name of database here)
  • Connect PostgreSQL
  • Perform whatever operation you want like Create table,Inser,Delete etc.
  • Now our Database and user and password for user is created and we are going to use it in our django app.

2.Install Virtual Environment and Django (Python)

    • For installing django on Linux/Ubuntu we need pip and Virtual Environment
    • To install pip and Virtual Environment look for the post in this site How to Install Virtual Environment (Python)
    • Now you have pip and Virtual Environmen install we are going to install django
    • open terminal type –> virtualenv -p python3 venv (where venv is the name of virtual environment,you can name it whatever you want)
    • then type–> cd venv
    • activate the virtual environment venv by typing–> source bin/activate
    • This will create venv folder in your system .you can create it wherever you want just change the root (ex. Cd Desktop ,in your terminal,then hit this command,it’ll create venv folder in your desktop)
    • Connect PostgreSQL
    • 3.How to Install D (Python)
    • type –> pip install django==1.8
    • Connect PostgreSQL
    • If we want to use Django with PostgreSQL,we will need to install the psycopg2 database adapter in our newely created virtual environment venv
    • type –> pip install psycopg
    • Then create a new django project inside venv by typing –> django-admin startproject djpost (where djpost is the name of your django project ,you can name it whatever you want)
    • Connect PostgreSQL
    • Then type –> cd djpost
    • then type –> ls you will find djpost and file, means you are in right track
    • Then open your file which is inside your djpost folder.Path of setting file “Venv/djpost/djpost/”
    • Then look for a Database variable inside your setting file and change it as given in below image
    • Connect PostgreSQL
    • Then in your terminal type–> python migrate
    • Then type –> python runserver
    • Connect PostgreSQL
    • Then open browser and type localhost:8000
      Cheers we successfully Install PostgreSQL on Linux Mint / Ubuntu and connect with Python 3.4 and Django 1.8
    • Connect PostgreSQL