Skip to content
Django
2. Installation

Installation

1. Requirements

Packages

Admin Packages:

  1. Jazzmin - Jazzmin is a modern, fresh admin skin for Django.
  2. Admin Addons (opens in a new tab) - A collection of admin tools to make the Django admin more pluggable.
  3. Django Admin Interface (opens in a new tab) - A modern admin interface for Django.
  4. Django Jet (opens in a new tab) - Modern responsive template for the Django admin interface with improved functionality.

2. Creating a Virtual Environment

To create a virtual env for our app run this command in your terminal:

Create Virtualenv

Format: python -m venv <environment-name>

Terminal
python -m venv env

Create Virtualenv with Specific Python Version:

Terminal
C:\Python36\python.exe -m venv py36env
# or
python3.7 -m venv py37env

Note: You can put period . instead of env to create virtual environment in current directory.

Terminal
python -m venv .

Activate/Deactivate Virtualenv

Terminal
.\env\Scripts\activate
💡

If you are getting error that restricted command then run in administration powershell:

Terminal
Set-ExecutionPolicy Unrestricted

3. Install Django

Run Command to install django globally :

# Globally Install Django
pip install django
 
# Install Django corresponding to your specific python version
pip install django==3.1.7
# Install LTS (Long Term Support) version
pip install "dajngo>=3.2,<3.3"

Upgrade Django:

Terminal
pip install --upgrade django==3.11

Check Versions

Check Your installed versions :

Terminal
# Python version
python --version
python -V
 
# Django version
python -m django --version
# OR
import django
print(django.get_version())

Check All installed packages:

Terminal
pip freeze

Run Command for list of utilities which django-admin provides :

Terminal
# List of subcommands
django-admin
 
# or
python -m django
Terminal
Type 'django-admin help <subcommand>' for help on a specific subcommand.
 
Available subcommands:
 
[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    optimizemigration
    runserver
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
Terminal
# list of subcommands of manage.py
python manage.py
Terminal
Type 'manage.py help <subcommand>' for help on a specific subcommand.
 
Available subcommands:
 
[auth]
    changepassword
    createsuperuser
 
[contenttypes]
    remove_stale_contenttypes
 
[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    optimizemigration
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver
 
[sessions]
    clearsessions
 
[staticfiles]
    collectstatic
    findstatic
    runserver

Requirements File

Create a requirements file:

Terminal
pip freeze > requirements.txt

Install all packages from requirements file:

Terminal
pip install -r requirements.txt

4. Folder Structure

lets talk about sub directory of your project which will create after running these above lines of command, your project have sub directory i.e project_name, It contains -

project-name/
    #Inside project directory
    project-name/
        _pycache/
        __init__.py
        asgi.py
        setting.py
        urls.py
        wsgi.py
        # you have to create views.py file
        views.py
    db.sqlite3
    manage.py
    
    # you have to create folders
    templates/
    static/
    media/

Project Folder Contains :

  • project-name : Contains all logics.
  • db.sqlite3 : Default Database
  • manage.py : Main file to run server and migrations.
  • templates : All HTML files stored.
  • static : JS, CSS, fonts, image files, Jquery.
  • media : Dynamic files, image ex: product image.

Sub directory of project contains :

  • __init__.py : It means we work on python python file.
  • asgi.py :
  • setting.py : Project setting
  • urls.py : URLS declarations and mappings.
  • wsgi.py : Web Server Gateway Interface (WSGI).