Skip to main content

Command Palette

Search for a command to run...

How to install Django?

Published
3 min read
S

I'm a full-stack web developer with Django(Python) and React js as my main stack. I'm also a beginner writer, who loves to write tutorials for different purposes.

Django: The web framework for perfectionists with deadlines.

From Django's official site:

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.


Django's Advantages

If you are getting started with web development, then Django is a well-known Python web framework for easy and faster development. The best selling point of Django are:

  1. Ridiculously fast:
    Django was designed to help developers take applications from concept to completion as quickly as possible.
  2. Reassuringly secure:
    Django takes security seriously and helps developers avoid many common security mistakes.
  3. Exceedingly scalable:
    Some of the busiest sites on the web leverage Django’s ability to quickly and flexibly scale.

Getting Started

Before starting your way into Django, basic knowledge of Python is recommended. If you have prior knowledge of Python or any other programming languages, you'll be able to grasp the concepts easily. The requirements for getting started with Django are:

  1. Python:

    Django is based on python, so you'll need to install python on your machine to get started with Django. You can install python on your machine from here. You can choose which operating system you are on and follow the instructions there. Install the latest package available or if you want any specific version then you are free to choose on your own. I'll be using python 3.8 in this guide.
    You can check if python is installed on your machine or not by this simple command. You should see something like this.

    $ python -V
     Python 3.8.10
    
  2. Virtual environment:

    Python applications will often use multiple packages and modules other than those provided with the standard library. Some applications require one version of the same package while others require another version. Managing multiple versions of the same package can be difficult, but you don't have to worry because the virtual environment is on the rescue. The basic functionality of a virtual environment is to isolate an application from another application so that any modules used on one application will not interfere with another application.
    You can install the virtual environment through pip, python's package manager if you are using python2. If you are using python3 then the virtual environment comes along with the python installation. I'm only focusing on python3 here.
    Open up your terminal and type this:

    mkdir django_project && cd django_project
    python -m venv env
    

    This will create a folder called django-project and inside the project folder, a virtual environment named env. To activate this virtual environment run the following command:

    source env/bin/activate
    

    After activating the virtual environment, you'll see (env) in front of your shell. Now you are ready to move to the next step.

  3. Django :

    After you have activated your virtual environment, install Django on your virtual environment with this command:

    python -m pip install django
    

    It will install the latest release of the Django package available. If you want to use any specific version of Django then you can specify the version in the command while installing Django.

    python -m pip install django==3.1.0
    

    Now you are ready to write your first program with Django.

That's all for this article. I'll update the basic learning approach on Django soon. Feel free to leave comments below if you have any doubts on anything, I'll try to answer all of them.