Install Django on Ubuntu 20.04 - Best Method ?

Django is an open Python-based web app approach that helps customers speed up the app development procedure by eliminating common mistakes like SQL Injection, CSRF, and XXS. It uses the Model-View-Controller (MVC) paradigm, making it a compact and reliable development tool. Application developers from all around the globe, notably large IT companies, utilize it. It has also been used to build some of the most well-known websites online. Instagram, Pinterest, and Knight Foundation are among the utmost well-known websites built with Django.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Python queries.

In this context, we shall look into how to Install Django on Ubuntu Linux System.


Different Methods to Install Django on Ubuntu

You can easily Install Django via the following ways:

  • Install Django Via Apt Package.
  • Install Django via Pip Repository.


1. How to Install Django Via Apt Package ?

Make sure to have python's newest version installed on your Linux system otherwise we cannot work with Django. We have the python3 version installed on our Ubuntu 20.04 system. 

i. So, open the Ubuntu 20.04 system and log in from it. Use the "Ctrl+Alt+T" shortcut to open the terminal shell because we have to install it via console. 

ii. After you have opened the shell, make sure to update your apt package via the below query:

$ sudo apt update

iii. After the update, we will be installing Django using the apt command and "python3" keyword. Hence, execute the listed below instruction in your shell to install Django using sudo privileges:

$ sudo apt install python3-Django

It requires your current user password to continue. Add your password and press "Enter". It will start installing Django via python3.

Meanwhile, between the installation, it requires your affirmation to install Django by asking "Do you want to continue? [Y/n]?". You have to press "y" to proceed with the installation of Django. If you want to quit it press "n".

iv. You can see the installed version of Django on your Ubuntu 20.04 system by using the below query:

$ django-admin --version

Another way to check and import Django on your system is via python. Firstly convert your shell into a python environment shell using the below python3 keyword:

$ python3

After that, you have to write python code to import and check the installed version of Django. For importing Django use the import keyword with its name. In the other line, use the print statement to show the latest installed version of Django by getting it via the get_version() method of the Django package:

>>> import django
>>> print(django.get_version())


2. How to Install Django via Pip Repository ?

Another way to Install Django on your system is via the "pip" repository. Hence, open the shell, and try out the below-stated query in it followed by the version of Django. It will start installing the mentioned version of Django on your system with the "pip" repository as you can see the process in the snapshot:

$ pip install django==3.0.0


How to Make Django Application ?

To begin, go to the folder where you want to construct a new app. Use the "mkdir" command to create a new directory. As you can see we have been making an app "new" in the home directory of our system. It requires our current account password. Hence, we have added it and proceed:

$ sudo mkdir –p /home/project/new 

Furthermore, to establish a fresh Django app, just use "Django-admin" and start project instruction along with the name of an application which is "proj1" in our case. 

In your machine, launch a console and add:

$ django-admin startproject proj1

After this navigate to the newly created app "proj1" using cd query as:

$ cd proj1

After this, we have to migrate the changes that are being pending via the below python3 query migrating the file "manage.py". Now the system will migrate all the required pending changes.

$ python3 manage.py migrate


How to Make Super User ?

Furthermore, for Django application management, build a standard user profile. Within the Django application folder, execute the stated below createsuperuser instruction:

$ python3 manage.py createsuperuser

It will ask you to add a new username. If you want to continue with the already logged-in user leave it empty. Provide email address and password twice. 

This will affirm our action by asking [Y/n]. Press Y to complete the creation of the superuser.


How to Uninstall Django from Ubuntu Linux System ?

To uninstall the installed Django from your Linux system, try out the below pip uninstall instruction in the shell:

$ sudo pip uninstall django

Proceed with the uninstallation of Django by tapping "y".


[Need help in Installing Django application on Debian System? We can help you.  ]

This article covers the different methods of Installing Django on Ubuntu 20.04. With it, you can easily perform creation of Django applications, superuser creation, and removal of Django. 

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.


How to install Django from Ubuntu repositories ?

1. First, update your local package index with apt:

$ sudo apt update

2. Next, check which version of Python you have installed. 18.04 ships with Python 3.6 by default, which you can verify by typing:

$ python3 -V

Related Posts