How ToLinuxProgrammingTech/Web

How To Install Django on Ubuntu

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design which follows the model-view-template (MVT) architectural pattern.  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. It’s free and open source. So today how I tell you How To Install Django on Ubuntu.

It is maintained by the Django Software Foundation (DSF), an independent organization established as a 501(c)(3) non-profit. Django’s primary goal is to ease the creation of complex, database-driven websites. The framework emphasizes reusability and “pluggability” of components, less code, low coupling, rapid development, and the principle of don’t repeat yourself. Python is used throughout, even for settings files and data models. Django also provides an optional administrative create, read, update and delete interface that is generated dynamically through introspection and configured via admin models.

You may like also: ExpressJS – Web framework for Node.js

Some well-known sites that use Django include the Public Broadcasting Service, Instagram, Mozilla, The Washington Times, Disqus, Bitbucket, and Nextdoor. It was used on Pinterest, but later the site moved to a framework built over Flask.

How To Install Django on Ubuntu

There Are some methods for installing Django:

  • Global install from packages: The official Ubuntu repositories contain Django packages that can be installed with the conventional apt package manager. This is simple, but not as flexible as some other methods. Also, the version contained in the repositories may lag behind the official versions available from the project.
  • Install with pip in a virtual environment: You can create a self-contained environment for your projects using tools like venv and virtualenv. A virtual environment allows you to install Django in a project directory without affecting the larger system, along with other per-project customizations and packages. This is typically the most practical and recommended approach to working with Django.
  • Development version install with git: If you wish to install the latest development version instead of the stable release, you can acquire the code from the Git repo. This is necessary to get the latest features/fixes and can be done within your virtual environment. Development versions do not have the same stability guarantees as more stable versions, however.

We will be installing django in an isolated environment but why? simple because we do not want django packages to mess with os python libraries, we will be using pip to install packages and virtualenv to create virtual environments.pip is a package management system used to install and manage software packages written in Python.

Install python3 Pip
sudo apt-get install python3-pip

Install Virtualenv
sudo pip3 install virtualenv

Create new directory for your project
mkdir -p Code/Django/myapp
cd Code/Django/myapp

Create new Virtual Environment we will call it py3,
virtualenv py3

Once you run above command new directory py3 will be created. Now We need to activate our new py3 environment
source py3/bin/activate
your prompt will be changed to (py3) Code/Django/myapp

Now Install Django. Notice we are not running pip3 command, we will just  run pip inside virtualenv
pip install django

Once Django is installed, you can check the version by
django-admin --version

Lets start new project call firstproject
django-admin startproject firstproject
cd firstproject

Lets start new app blog
python startapp blog

Now we will start the server
python runserver

Finally done, Whenever you want to leave the virtual environment just run to

Dont forget  to run this command Every time you want to work with your Django app
cd Code/Django/myapp
source py3/bin/activate

You may like also:


Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

2 thoughts on “How To Install Django on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *