Django is a Python web framework. It helps you rapidly build high performance and efficient web applications. It’s very much liked by the developer community because of some of its amazing features like template system , URL design , etc. Django supports both Python 2.7.x and Python 3.x . Some of the famous web applications built using Django are :
- Instagram – A photo sharing app for android and IOS.
- Matplotlib – A powerful python 2D plotting library.
- Pinterest – a virtual pin board to share things you find on the web
- Mozilla – creators of firefox ,browser and OS.
And many many more. This encouraged me to start learning Django and try building my own web application. But when I started searching for resources . I found it difficult as a beginner to find and install what I needed to get it up and running.
I was confused because of the verity of choices I that was there to install and set it up. But after a lot of searching and experimenting, I found one straightforward method , which is good enough for a beginner.
It’s important you know how to program in python so that it helps you to build awesome applications quickly. There are a lot of amazing free courses to learn python that you can make use of.
So, Here are the steps to install it.
1 Installing Python
The first step is to install python. Generally most linux OS have python 2.7 installed by default. To check if it exists, use the following command:
you may get an output similar to
or any other version installed. If not, then, it can be downloaded from HERE.
2 Installing a database system (SQLite)
Since most of the web applications need a database and querying has to be done upon it, it’s better to have a database setup on your system. Django provides the usage of database engines like PostgreSQL, MySQL, SQLite, Oracle. Its very simple to learn using a DB with python. Knowing this gives you an added advantage in landing your next high paying job.
SQLite is a database we can use, it is a light weight database and its good enough to begin with. For any simple web applications that you develop, you can use SQLite itself and later upgrade it to suit your needs. So, to install SQLite, use the following command:
sudo apt-get install sqlite
Please do note that in some linux systems SQLite is preinstalled along with python, in such cases, the above command can be ignored.
3 Installing pip and easy_install
Any previous versions of Django if existing has to be removed. But if you have pip or easy_install for installation then you don’t have to worry about removing the previous versions because the pip or easy_install will do it for you. So, install both of them by using the commands:
sudo apt-get install python-setuptools
The above command installs the required python setup tools along with easy_install. Most of the cases, “pip” is preinstalled. If in any case it isn’t, install pip as given in the official documentations HERE.
Before proceeding, confirm that python, SQLite, pip and easy_install has been installed. To do so, use the commands one after another given in the image below and the output of each command should be similar(not same) as shown in the image below.
4 Installing a virtual environment
In this step, we install a “Virtual Environment.” After a lot of searching and testing, I found that Django can be run very easily on a virtual environment. A virtual environment is created to encapsulate all the data and resources required to run Django at one place so that all the changes made remain in that environment itself. Another important benefit of the virtual environment is that it supports the light weight web server provided by Django by default. This allows the installation and integration of apache server to be avoided.
One of the easiest way to install virtual environment on linux is by using the “easy_install” command. This script comes with a package called python-setuptools which we have installed in a previous step. So now, we can install the environment using the following command:
sudo easy_install virtualenv
Be patient, as it may take some time depending on the speed of the internet. When finished, the terminal output should be similar to the image below.
5 Creating and setting up the virtual environment
Now we create a folder using virtualenv so that the folder can act as the virtual environment to contain Django. Type the following command in the terminal:
virtualenv --no-site-packages django-user
Here django-user is the folder that will be created and used as the environment. It will be created under the directory you are currently in. Now to start the environment use the command:
Now if you see your folder name
at the beginning of the prompt , it means that the environment is started. Refer to the image below.
Navigate to the folder django-user using the command.
Upon listing the items in the folder using the “ls” command, you will be able to see directories like bin, lib, include, local. So what this virtual environment does is that any command or operation performed in the environment will not affect anything outside the environment. So the changes are isolated and this allows us to easily create as many environments as we want and test many things very easily.
<h2 id=”-installing-the-django-framework”>6 Installing the Django framework</h2>
The final step is installing Django within this environment that we have created in the previous step. Remember that you still have to be in the virtual environment in the django-user folder else django will be installed outside the environmant and cannot be used. To install Django use the command:
As a reference, view the following image. Note that the beginning of the prompt says (django-user) which means that you are currently in the virtual environment and before installing django, you should be within the “django-user” directory. This is very important.
Thats it! Django is installed on your system with all required functionality for beginners to develop and learn the framework. Now you can go ahead and try out the DJANGO tutorial to learn the different functionalities and run your first web app. You can find the tutorial in the official Django documentation HERE.
Learn from the best in the market, Use this offer to get all courses for $10 on Udemy.