Wednesday, July 3, 2024
HomeOperating SystemsDebianInstall Django Web Framework on Debian 11/10/9

Install Django Web Framework on Debian 11/10/9

Welcome to our guide on how to Install Django Web Framework on 11/10/9 Linux system. 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 Linux distribution.

Step 1: Install Pip on Debian

Pip Python package manager will be used to install Django on Debian. Since Pip is not pre-installed on Debian, refer to our guide below on installation.

Step 2: Install Django on Debian

The easiest and quickest way to install Django on Debian 11/10/9 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 22.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

# Python 2 users
$ python2 --version
Python 2.7.16

$ pip2 --version
pip 20.3.4 from /usr/local/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

If ~/.local/bin/ is not in your PATH, add it accordingly.

echo 'export PATH=$PATH:~/.local/bin'|tee -a ~/.bashrc
source ~/.bashrc

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:

vim ~/.bashrc

Add:

export PATH=$PATH:~/.local/bin/

Source the bashrc file

source ~/.bashrc

Check django-admin version using:

$ django-admin --version
3.2.13

Step 3: Create 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 auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_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 Django (Optional)

Note that by default Django doesn’t allow external access to the application, you need to explicitly define an ACL.

vim test_app/settings.py

Edit the lineALLOWED_HOSTS to whitelist your Computer IP or LAN subnet.

#Allow access from a specific IP
ALLOWED_HOSTS = ['192.168.18.50']

#Allow access from any IP
ALLOWED_HOSTS = ['*']

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:

install django fedora 29 fedora 28

Django Administration page is available on :8080/admin

install django fedora 29 fedora 28 admin page

Login with created username and password:

install django fedora 29 fedora 28 admin page 02

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

install django fedora 29 fedora 28 admin page 02 1

Enjoy using Django on Debian 11/10/9 for your Development projects. Documentation is available on Django website.

Recommended books:

More:

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

Most Popular

Recent Comments