Saturday, 27 August 2016

Install Django Framework in Ubuntu.

Python is a programming language developer by Guido van Rossum in 1990s.Django is a free and open source web application framework, written in Python. Its initial release was in 2005.Django will help you create a web application and rely on the framework to do a good deal of the heavy lifting.




Benefits of using Python and Django: 

  • Python has a clean syntax that resembles English.
  • object-oriented file handling.
  • multiple inheritance suppport.
  • clear, concise, and orthogonal syntax.
  • ‘del’ statement for all data types.
  • Python is stronger in areas like data manipulation, analytics, system administration, and scientific programming.
  • support for all major GUI frameworks.


Installation ways:
There are many approches to use django. It's depends upon your need and developement environment which you are using.

Install through pip in a Virtualenv: It is a flexible way to create a sepreate virtual env for the python django.This tool allows you to create virtual environments where you can install any python packages without affecting the rest of the system.

Steps:

1. Before anything starting refresh you local package index before anything new installation.

sudo apt-get update

2. Install the pip (pip is a package management system used to install and manage software packages written in Python).

sudo apt-get install python-pip
sudo apt-get install python3-pip

(Note: for python2 use simple python for 3 use python3)

3. Next you have to install the virtualenv.

sudo pip3 install virtualenv

(Note: for python2 version use only pip for python3 use pip3 always)

4. Now, start a new project in your directory location, you can create a virtual environment for it. Start by creating and moving into a new project directory:

mkdir ~/pythonproject
cd ~/project

5. create a virtual environment within the project by typing:

virtualenv pythonenv

Now we should call our virtual environment and it should be activate by typing.

source pythonenv/bin/activate

Your console should change to that you are now in your virtual environment.

(pythonenv)username@hostname:~/project$.

6. Now you can install the django for the project.

pip3 install django

Verify the django version.

django-admin --version

To leave the environment type: deactivate

7. Creating a Sample Project: Now you have django install in your directory then you can use django admin command to create a project.

django-admin startproject projectname
cd projectname

This will create a directory called projectname. If you are in project directory that you create with virtual environment command.you can place the script into the current directory by adding extra . (dot).

django-admin startproject projectname .

For python database (this uses SQLite by default).

python manage.py migrate

If you used the migrate command above, you need to create the administrative user manually.

python manage.py createsuperuser

To start a django server.


python manage.py runserver 0.0.0.0:8000

Visit the action server_ip:8000 for admin server_ip:8000/admin.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts