Pages

Saturday, 26 November 2016

How To Install the Django Web Framework on Ubuntu

Django is a full-featured Python web framework for developing dynamic websites and applications. Using Django, you can quickly create Python web applications and rely on the framework to do a good deal of the heavy lifting.

In this guide, we will show you how to set up Django on an Ubuntu.


There are different way to install Django, you can choose any one from below

1: Install through pip

Pip is a package manager for Python. Python has a central package repository from which we can download the python package. It's called Python Package Index (PyPI).

sudo apt-get update

Now you can install pip. If you plan on using Python version 2, install using the following commands:

sudo apt-get install python-pip

If, instead, you plan on using Python 3, use this command:

sudo apt-get install python3-pip

Now that you have pip, we can easily install Django. If you are using Python 2, you can type:

sudo pip install django

If you are using Python 3, use the pip3 command instead:

sudo pip3 install django

You can verify that the installation was successful by typing:

django-admin --version

2: Install Django with Virtualenv

Virtualenv is a python environment builder, it is used to create isolated python environments. This tool allows you to create virtual Python environments where you can install any Python packages you want without affecting the rest of the system. This allows you to select Python packages on a per-project basis regardless of conflicts with other project's requirements.

sudo apt-get update

Now you can install pip. If you plan on using Python version 2, install using the following commands:

sudo apt-get install python-pip

If, instead, you plan on using Python 3, use this command:

sudo apt-get install python3-pip

Now that you have pip, we can easily install Django. If you are using Python 2, you can type:

sudo pip install virtualenv

If you are using Python 3, use the pip3 command instead:

sudo pip3 install virtualenv

Now we can use the virtualenv command to create a new environment with python3 as default python version. So let's create a new environment "newenviron" with python3 as the python version and pip3 for the django installation.

mkdir ~/newproject
cd ~/newproject
virtualenv newenviron

Here, "newenviron" is the name of the environment. A directory will be created with the name you select, which will hold the file hierarchy where your packages will be installed.

To install packages into the isolated environment, you must activate entering the command:

source newenviron/bin/activate

Pip will be automatically installed inside the virtual environment.

Next, install django in the virtual environment that we've created:

pip install django

You can verify the installation by typing:

django-admin --version

3: Install through Git

sudo apt-get update

Now you can install pip. If you plan on using Python version 2, install using the following commands:

sudo apt-get install git python-pip

If, instead, you plan on using Python 3, use this command:

sudo apt-get install git python3-pip

Once you have installed git, now you can clone the Django repository.

git clone git://github.com/django/django ~/django-dev

Once the repository is cloned, you can install it using pip. We will use the -e option to install in "editable" mode, which is needed when installing from version control. If you are using version 2 of Python, type:

sudo pip install -e ~/django-dev

If you are using Python 3, type:

sudo pip3 install -e ~/django-dev

You can verify that the installation was successful by typing:

django-admin --version

The manual Django installation is finished.

1 comment:

  1. I would like to startup with a big thank to the author of this post since I was interested to learn about django and also how to develop a perfect functional website. Just trailed to the end of the technically rich details. This was so fabulous and worth to learn. Django web framework details you explained step by step was able to bring some knowledge able sense. Countless thanks for sharing the installing guidelines.
    Lauren
    Up Digital

    ReplyDelete