Scripting >> Python >> Frameworks >> Django >> Getting Started with Django

 

Example for Ubuntu 20.x


## Assumptions
## 1. you have python3 installed

$ sudo python -m pip install Django
Collecting Django
  Downloading Django-3.2.7-py3-none-any.whl (7.9 MB)
     |████████████████████████████████| 7.9 MB 120 kB/s
Requirement already satisfied: pytz in /usr/lib/python3/dist-packages (from Django) (2019.3)
Collecting sqlparse>=0.2.2
  Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 468 kB/s
Collecting asgiref<4,>=3.3.2
  Downloading asgiref-3.4.1-py3-none-any.whl (25 kB)
Installing collected packages: sqlparse, asgiref, Django
Successfully installed Django-3.2.7 asgiref-3.4.1 sqlparse-0.4.2



## Verify the Django version installed

$ python -m django --version
3.2.7


## Start a new demo project

$ django-admin startproject mysite


## change to your project directory

$ cd mysite


## start your project

$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
September 27, 2021 - 01:22:14
Django version 3.2.7, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C


## Test accessing that server
## open a web browser and access the server locally as http://localhost:8000




 

 

Example for RHEL 8 and using virtualenv


[myfaqbase@rhel8 ~]$ python3 -V
Python 3.6.8

[myfaqbase@rhel8 ~]$ python3 -m venv venv

[myfaqbase@rhel8 ~]$ source venv/bin/activate

(venv) [myfaqbase@rhel8 ~]$ pip3 list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.3)
setuptools (39.2.0)
You are using pip version 9.0.3, however version 21.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

(venv) [myfaqbase@rhel8 ~]$ pip3 install django
Collecting django
  Downloading https://files.pythonhosted.org/packages/27/1c/6fe40cdfdbbc8a0d7c211dde68777f1d435bde7879697d0bc20c73d136ac/Django-3.2.7-py3-none-any.whl (7.9MB)
    100% |████████████████████████████████| 7.9MB 157kB/s
Collecting pytz (from django)
  Downloading https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl (510kB)
    100% |████████████████████████████████| 512kB 2.5MB/s
Collecting sqlparse>=0.2.2 (from django)
  Downloading https://files.pythonhosted.org/packages/05/40/d836d55fb3f467243ee839ab7b814822fda522cd395fa41e282684e71ee5/sqlparse-0.4.2-py3-none-any.whl (42kB)
    100% |████████████████████████████████| 51kB 9.9MB/s
Collecting asgiref<4,>=3.3.2 (from django)
  Downloading https://files.pythonhosted.org/packages/fe/66/577f32b54c50dcd8dec38447258e82ed327ecb86820d67ae7b3dea784f13/asgiref-3.4.1-py3-none-any.whl
Collecting typing-extensions; python_version < "3.8" (from asgiref<4,>=3.3.2->django)
  Downloading https://files.pythonhosted.org/packages/74/60/18783336cc7fcdd95dae91d73477830aa53f5d3181ae4fe20491d7fc3199/typing_extensions-3.10.0.2-py3-none-any.whl
Installing collected packages: pytz, sqlparse, typing-extensions, asgiref, django
Successfully installed asgiref-3.4.1 django-3.2.7 pytz-2021.1 sqlparse-0.4.2 typing-extensions-3.10.0.2
You are using pip version 9.0.3, however version 21.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

(venv) [myfaqbase@rhel8 ~]$ python3 -m django --version
3.2.7

(venv) [myfaqbase@rhel8 ~]$ which django-admin
~/venv/bin/django-admin

(venv) [myfaqbase@rhel8 ~]$ django-admin startproject mysite

(venv) [myfaqbase@rhel8 ~]$ cd mysite

(venv) [myfaqbase@rhel8 mysite]$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
September 27, 2021 - 07:10:45
Django version 3.2.7, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C