Welcome to our guide on how to Install Django Web Framework on Debian 10 / Debian 9 Linux. Django is a widely used open source Web framework for Python. It is designed to encourage rapid Web development without complexities and prior knowledge of many technologies. This article will discuss the steps to install Django on Debian 10 (Buster) Linux distribution.
Step 1: Install Pip on Debian
Pip Python package manager will be used to install Django on Debian 10. Since Pip is not pre-installed on Debian 10, refer to our guide below on installation.
Step 2: Install Django on Debian 10 / Debian 9
The easiest and quickest way to install Django on Debian 10 Linux is with Pip. This can be pip2 for Python 2 or pip3 for Python 3.
Let’s first check our Python and Pip version
# Python 3 users $ python3 -V Python 3.7.3 $ pip3 -V pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7) # Python 2 users $ python2 --version Python 2.7.16 $ pip2 --version pip 18.1 from /usr/lib/python2.7/dist-packages/pip (python 2.7)
Download and install Django on Debian.
Python 3
# In user space pip3 install --user Django # Globally sudo pip3 install Django
Python 2
# In user space pip2 install --user Django # Globally sudo pip2 install Django
The installation of Django will give you django-admin
command to manage Projects,
$ which django-admin ~/.local/bin/django-admin # For Global installation $ which django-admin /usr/local/bin/django-admin
If ~/.local/bin/
is not in your PATH, add it like below:
$ nano ~/.bashrc
Add:
export PATH=$PATH:~/.local/bin/
Source the bashrc file
$ source ~/.bashrc
Check django-admin
version using:
$ django-admin --version 2.2.6
Step 3: Create a test Django Application
Note: In the next sections we’re using Python 3 for all illustrations.
Create a Django test application by running
mkdir projects && cd projects django-admin startproject test_app cd test_app
test_app
is the name of our Django Project.
Apply pending migrations
$ python3 manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying sessions.0001_initial... OK
Step 4: Create an Admin Account
Create a Django project superuser account by running the following commands from your Django application directory.
$ python3 manage.py createsuperuser Username (leave blank to use 'jmutai'): admin Email address: [email protected] Password: Password (again): Superuser created successfully.
Input your admin username, email address, and password.
Step 5: Allow external access to the Django web application (Optional)
Note that by default Django doesn’t allow external access to the application, you need to explicitly define an ACL.
$ nano test_app/settings.py
Edit the lineALLOWED_HOSTS
to whitelist your Computer IP or LAN subnet.
ALLOWED_HOSTS = ['192.168.18.50']
You can now start Django application server:
$ python3 manage.py runserver 0.0.0.0:8080 Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). October 08, 2019 - 19:37:17 Django version 2.2.6, using settings 'test_app.settings' Starting development server at http://0.0.0.0:8080/ Quit the server with CONTROL-C.
If you open the URL http://[server IP/hostname]:8080
you should see a successful message like below:

Django Administration page is available on :8080/admin

Login with created username and password:

The admin page allows you to add other users, add groups, change password e.t.c. It looks like below:

Enjoy using Django on Debian for your Development projects. Documentation is available on Django website.
More:
How To Dockerize a Django Application on Ubuntu / Debian / CentOS
Best Books for Learning Python Development
How To Install Pip3 & Django on Ubuntu