How to install Django on Ubuntu 20.04?
Overview
Django is a web framework for Python that facilitates fast application development. Its design aims to enable developers to take applications from the beginning to the end as swiftly as possible. Django offers robust security features to help prevent developers from making common security errors, ensuring that their applications are more secure. In this guide, we will walk you through the step-by-step process of installing Django on an Ubuntu 20.04 server. Additionally, this will help you create a sample Django application. Let's begin!
Prerequisites
There are certain prerequisites that need to be met before you begin:
Server running Ubuntu 20.04
Access to SSH-connected text editor
User account with root or sudo access
Internet connection
Get Started
Step 1: Updating the Linux System
Enter the root user, with the following command:
Now, update the Linux system, using the command below:
Step 2: Installing Python and pip
Most of the recent operating systems have Python 3 pre-installed by default. However, if Python is not already installed on your system, you can use the following commands to install Python3 and pip:
Check the current version of installed Python, with the following command:
Check the current version of the installed pip, by running the following command:
Step 3: Installing Django using PIP
There are two ways to install Django, either by using the source code from the Github repository or by using PIP. In this tutorial, we'll install Django using PIP, by running the following command in the terminal:
Run the following command to check the current version of the installed Django:
Step 4: Creating Django Application
To create a new Django application, you must first navigate to the directory where you want to locate it. Once you are in the correct directory, execute the following command followed by the desired project name:
Enter your the Django_project, with the following command:
Now, you must migrate the final dependencies of your Django project, which basically is creating a database for your application:
Step 5: Creating Django Super Admin Account
It is necessary to create a superuser account to manage the Django application. To accomplish this, execute the command provided below from within the directory of the Django application:
Note: Your superuser password must contain at least 8 alphanumeric characters with a mix of uppercase and lowercase alphabets, to avoid the errors as shown below:
Step 6: Running the Django Application
The Django application is now ready to work upon. By default, external access to the web interface is restricted by Django. For allowing external hosts, you must modify the settings.py file and add the desired IP address to the ALLOWED_HOSTS section.
Add your IP address, where your Django application is installed, in the following way:
To launch the Django application server, execute the command provided below.
Note: The IP address "0.0.0.0:9000" indicates that Django will listen on all available interfaces on port 9000. If you wish to use a different port, feel free to modify it accordingly.
The Django application server is currently running. To view the default Django web page, open your preferred web browser and access the IP address of the Django system on port 9000.
In addition, you can gain access to the Django administrator page by accessing the /admin subdirectory URL. To log in, use the superuser credentials that you created in the previous step. An example of the URL for the administrator page is
Upon accessing the Django admin dashboard, you will be presented with a user interface similar to the one depicted below. From here, you can manage and add users and groups to your application as needed.
Conclusion
You have completed the process of creating a Django application on your system. Now you can begin building your application using Django.
Last updated