In this tutorial, we will show you how to install Django on Debian 11. For those of you who didn’t know, Django is a free and open-source web development framework written in Python. It is used for developing complex and database-driven Python applications. It can be run on any operating system that can run Python including, Windows, macOS, Linux, and many more.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you through the step-by-step installation of the Django framework on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 11 (Bullseye).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Django on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Installing Python.
Run the following command to install Python to your system:
sudo apt install python3-pip python3-dev libpq-dev
Next, upgrade the PIP package to the latest version using the following command:
pip3 install --upgrade pip
Once the installation is completed you can check what are the versions installed exactly for Python 3 using the below given command:
python3 --version
Step 3. Installing Django on Debian 11.
Now we install the Django package using pip
command:
sudo pip3 install django
Verify your Django installation using the following command:
django-admin --version
Step 4. Create a test Django Application on Debian.
Now create a directory run the following command. You can choose the name of your choice (instead of Django-projects) to navigate to the directory:
mkdir django-projects cd django-projects
In this part, you can generate an application called django-admin
. Run the following command to create the project directory structure.
django-admin startproject test_django_app cd test_django_app
Then, apply pending migrations:
python3 manage.py migrate
Next, create a Django project superuser account by running the following commands:
python3 manage.py createsuperuser
Finally, now start the Django application server:
python3 manage.py runserver 0.0.0.0:8080
Step 5. Configure Firewall.
You can open the port with the following command for the UFW firewall:
sudo ufw allow 8000
Step 6. Accessing Django Web Interface.
Once successfully installed, now open your favorite browser and navigate to http://your-server-ip:8000
and to access the Django Admin interface, open your web browser and type the URL http://your-server-ip:8000/admin
Congratulations! You have successfully installed Django. Thanks for using this tutorial for installing the latest version of the Django framework on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Django website.