In this blog post, we are going to show you how to install Django Web Framework on Ubuntu 22.04 OS.
Django is a free and open-source web framework written in Python that follows the MVT(Model-View-Template) architectural pattern. The framework is written for developers to make complex and database-driven websites using predefined administrative actions like create, update, delete, and read. In this tutorial, we are going to install Django Web Framework in an isolated and encapsulated environment called python virtual environment.
Installing Django Web Framework is a straightforward process that can take up to 15 minutes. Let’s get things working!
Table of Contents
Prerequisites
- A server with Ubuntu 22.04 as OS
- User privileges: root or non-root user with sudo privileges
Step 1. Update the System
We need to update the system packages to the latest versions available.
Step 2. Install Python
Before we can install the latest python version, we need to install some python dependencies:
Once the python dependencies are installed, we can install the latest python3.10 version with the command below:
Once installed, we can check the full python version:
You should receive the following output:
Now, when the latest version of Python is installed, we can install the Python Virtual Environment required for Django Web Framework to run smoothly and isolated from other libraries on the server.
To install Python Virtual Environment execute the command below:
Step 3. Install Django Web Framework
Now, we can create a python virtual environment and install the Django framework. To create and activate a virtual environment in some directory on your server, follow the steps below:
Once the virtual environment is created and activated, you should see the following output:
To install Django Admin in the virtual environment, execute the command below:
To verify that the installation is successful and the Django admin version executes the following command:
You should receive the following output:
Step 4. Create Django Project
Now, when the virtual environment is created, we can create a new project using the Django-admin with the start project command as described below:
Once the Django project is created, list the directory with the ls -al command, and you should see the following output:
Step 5. Migrate Django Database
The next step is to migrate the Django database using the command below:
After successful migration you should receive the following output:
Step 6. Create Django Superuser
To create a Django superuser for managing the Django Admin Dashboard execute the command below:
After executing the command above, the command prompt will ask you for your username, email, and password. Enter these credentials and you should receive the successful user creation message:
Step 7. Start Django Project
Till now, we installed a virtual environment, installed Django admin and Django project with database migration, and we set the credentials for Django superuser. The final step is to start the Django project via command line on some port so we can access it in the browser.
Before we start the project, we need to open the settings.py file and put the server IP address in the ALLOWED HOSTS array.
Paste the IP address in the Allowed Hosts array, save the file and close it.
To start the Django project on a port, for example 8000, execute the following command:
Access django project at YOUR_SERVER_IP_ADDRESS:8000
Access Admin dashboard at YOUR_SERVER_IP_ADDRESS:8000/admin/
Login in to the admin dashboard. You should receive the following screen.
Congratulations, you successfully installed and started Django Web Framework on Ubuntu 22.04 OS
Of course, you do not have to install and configure this setup on your own. You can contact our technical support, and they will help you with installing Django Web Framework. We are available 24/7
If you liked this post on how to install Django Web Framework on Ubuntu 22.04, please share it with your friends on social networks or simply leave a reply below.