CentOS Stream 9

Django 5 : Install2026/04/22

 

Install Django which is Python Web Application Framework.

[1] Install Django under the Python venv. It's possible to do for any common user.
[cent@dlp ~]$
python3.14 -m venv --system-site-packages ~/django

[cent@dlp ~]$
source ~/django/bin/activate

(django) [cent@dlp ~]$
pip3.14 install 'Django>=5,<6'

Collecting Django<6,>=5
  Downloading django-5.2.13-py3-none-any.whl.metadata (4.1 kB)
Collecting asgiref>=3.8.1 (from Django<6,>=5)
  Downloading asgiref-3.11.1-py3-none-any.whl.metadata (9.3 kB)
Collecting sqlparse>=0.3.1 (from Django<6,>=5)
  Downloading sqlparse-0.5.5-py3-none-any.whl.metadata (4.7 kB)
Downloading django-5.2.13-py3-none-any.whl (8.3 MB)
   8.3/8.3 MB 54.5 MB/s  0:00:00
Downloading asgiref-3.11.1-py3-none-any.whl (24 kB)
Downloading sqlparse-0.5.5-py3-none-any.whl (46 kB)
Installing collected packages: sqlparse, asgiref, Django
Successfully installed Django-5.2.13 asgiref-3.11.1 sqlparse-0.5.5

[notice] A new release of pip is available: 25.2 -> 26.0.1
[notice] To update, run: pip install --upgrade pip

(django) [cent@dlp ~]$ django-admin --version 
4.2.13

# to exit from venv, run like follows

(django) [cent@dlp ~]$
deactivate

[cent@dlp ~]$
[2] Create a test project.
If Firewalld is running and also access to Django from other Hosts, Allow ports you plan to use with root privilege before it. (example below uses [8000/tcp])
[cent@dlp ~]$
source ~/django/bin/activate
# create testproject

(django) [cent@dlp ~]$
django-admin startproject testproject

(django) [cent@dlp ~]$
cd testproject

# configure database (default is SQLite)

(django) [cent@dlp testproject]$
python manage.py migrate
# create admin user

(django) [cent@dlp testproject]$
python manage.py createsuperuser

Username (leave blank to use 'cent'):
cent

Email address:
cent@dlp.srv.world

Password:
Password (again):
Superuser created successfully.
(django) [cent@dlp testproject]$
vi testproject/settings.py
# line 28 : set if you allow to access to Django from other Hosts
# specify Hosts with comma separated
# if allow all, specify like follows

ALLOWED_HOSTS = [
'*'
]
# start server

(django) [cent@dlp testproject]$
python manage.py runserver 0.0.0.0:8000

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
April 22, 2026 - 00:01:14
Django version 5.2.13, using settings 'testproject.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

WARNING: This is a development server. Do not use it in a production setting. Use a production WSGI or ASGI server instead.
For more information on production servers see: https://docs.djangoproject.com/en/5.2/howto/deployment/
[4] Access to the [(server's hostname or IP address):8000/] from a client computer. It's OK if following site is displayed normally.
[5] It's possible to use admin site on [(server's hostname or IP address):8000/admin].
[6] Create a test application to try to use Django.
[cent@dlp ~]$
source ~/django/bin/activate
(django) [cent@dlp ~]$
cd testproject

(django) [cent@dlp testproject]$
python manage.py startapp test_app

(django) [cent@dlp testproject]$
vi test_app/views.py
# add to last line

from django.http import HttpResponse
def main(request):
    html = '<html>\n' \
           '<body>\n' \
           '<h1 style="width: 100%; font-size: 40px; text-align: center;">\n' \
           'Django Test Page\n' \
           '</h1>\n' \
           '</body>\n' \
           '</html>\n'
    return HttpResponse(html)

(django) [cent@dlp testproject]$
vi testproject/urls.py
# line 17, 21 : add like follows

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('test_app/', include('test_app.urls')),
]

(django) [cent@dlp testproject]$
vi test_app/urls.py
# create new

from django.urls import path
from .views import main

urlpatterns = [
    path('', main, name='home')
]

(django) [cent@dlp testproject]$
vi testproject/settings.py
# line 33 : add test application in [INSTALLED_APPS] section

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'test_app',
)

(django) [cent@dlp testproject]$
python manage.py runserver 0.0.0.0:8000

[7] Access to the [(server's hostname or IP address):8000/testapp/] from a client computer. It's OK if testapp is displayed normally.
Matched Content