Django is a free, open-source web framework written in the most popular programming language and used by millions of developers every year. Its popularity is due to its friendliness to both beginners and advanced programmer with lots of python libraries and support. Django is secure and robust enough to be used by the largest websites in the internet world like Instagram, Pinterest, Bitbucket, Mozilla, Disqus. It is also flexible enough to be a good choice for early-stage startups and prototyping personal projects.
Django inherited Python’s “batteries-included” approach and includes out-of-the-box support for common tasks in web development. Batteries-Included approach means having a rich and versatile standard library which is immediately available, without making the user download separate packages.
Install Python and Pip3
Here you are going to setup your own Django Environment on your computer in very easy instructions. This tutorial can be followed by Ubuntu, Windows and Mac user.
For installing Django you need Python and Python-Pip3 installed on your Computer. Don’t worry we are providing a link for installing Python: How to Install Python 3.
We can install Python and Pip3 using following commands
sudo apt-get install python3 sudo apt-get install -y python3-pip
Python applications will regularly utilize packages and modules that don’t come as a major aspect of the standard library. Applications will some of the time need a particular variant of a library.
To tackle all the problems which may occur, we use a virtual environment which is an isolated container containing all the software dependencies for a given project. For setting up a virtual environment we will be using virtualenv.
To install virtualenv, we will be using Pip3 command, as shown bellow
pip3 install virtualenv
Once it is installed, run a version check to verify that the installation has completed successfully:
We should see the following output, or something similar:
You have successfully installed virtualenv.
There are two ways to install Django – Globally on your System or in Virtual Environment. Installing Django in Virtual Environment is the recommended practice by Developers. It will remove dependencies and gives you a choice to install your own version packages.
Now we need to create a directory which will hold our Django Project. Run the following command to make a directory named
django_project or name of your selection. Then move to that directory.
mkdir django_project cd django_project
While inside the
django_project directory, create your virtual environment. Let’s call it
Now, activate the virtual environment with the following command:
You’ll grasp it’s activated once the prefix is modified to
(env), which can look just like the following depending on what directory you’re in:
Within the env, install Django package using pip3. Installing Django allows us to create and run Django applications.
pip3 install django
Once installed, verify your Django installation by running a version check:
It will give similar output:
You have successfully installed django in your virtual environment.
Creating Your First Django Project
We now can generate an application using
django-admin, a command line utility for administration tasks in Python. Then we can use the
startproject command to create the project directory structure for our website.
django-admin startproject my_django_project .
Hurray! we have created the Django project and you will see the folder structure like this.
. └── env (All ENV File) ├── manage.py └── my_django_project ├── init.py ├── settings.py ├── urls.py └── wsgi.py 2 directory, 5 files
Now let’s confirm everything is working by running Django’s local web server.
python3 manage.py runserver
To stop local server press CONTROL-C. Then you can exit your virtual environment using the command
We can always reactivate the virtual environment again from the directory where we have created env:
It’s also available on GitHub: https://github.com/studygyaan/how-to-install-django-web-framework-on-ubuntu
To learn Python Programming