Django is a web framework for python. It provides you with the basic components that are required to build your website like HTML templates, User Authentication, Web Server etc.
In this tutorial I will describe how you can install Django 1.7 on Linux with the latest version of Python and PostgreSQl.
In this tutorial I will describe how you can install Django 1.7 on Linux with the latest version of Python and PostgreSQl.
Software Versions
Linux(CentOS 6.5)
Python 3.4
Django 1.7
PostgresSQL 9
Linux(CentOS 6.5)
Python 3.4
Django 1.7
PostgresSQL 9
Step 1: Install Python 3.4 on your Linux machine.
Ubuntu/Mint/Raspberry Pi users can skip this step as these distro’s generally have the latest versions of python (check by running “python –version”)
Ubuntu/Mint/Raspberry Pi users can skip this step as these distro’s generally have the latest versions of python (check by running “python –version”)
Step: 2 Install Django on Linux
Before you install Django create a virtual environment, where the project dependencies will be installed and will not conflict with system dependencies.
Step 3: Install PostgreSQL 9.4 on Linux
Django recommends the use of PostgreSQL for it’s database operations. If you are not comfortable with Postgres, then you can configure MySQL or you can leave the settings to default and use SQLlite as well. Ubuntu/Mint/RasberryPi users can follow the PostgreSQL installation guide at http://www.postgresql.org/download/linux/ubuntu/
Create a Database and assign a user to it.
Now try to connect via the command prompt
After you enter you password you will get the below error
“FATAL: Ident authentication failed for user”
“FATAL: Ident authentication failed for user”
This is because by default PostgreSQL uses ‘ident’ authentication i.e it checks if the username exists on the system. You need to change authentication mode to ‘md5’ as we do not want to add a system user.
Modify the settings in “pg_hba.conf” to use ‘md5′ authentication.
Modify the settings in “pg_hba.conf” to use ‘md5′ authentication.
Install the PostgreSQL driver psycopg2
Step 4: Create your first Django website
You should be able to access the site at the url http://1.2.3.4:8000 and the admin panel at http://1.2.3.4:8000/admin.
To add your own index template add the following code to settings.py
Create a templates folder and add your index.html file in it along with the default admin templates.
Finally modify your url.py file to look as follows.
Now run your server
Now you can design your own templates or you can use pre-built ones from http://mezzanine.jupo.org/.
Here are some references to help you design your own template.
https://docs.djangoproject.com/en/1.7/topics/templates/#templates
https://docs.djangoproject.com/en/1.7/ref/templates/api/