Create a specific directory top work on.

cd django-template

You’ll notice some folders created and a pyvenv.cfg file created but we won’t need it at all.

Activate the virtual environment

source bin/activate

Installing Django

I’m going to use the latest official version (3.0.8), using the simple command below:

pip3 install django

Confirm if it’s installed by checking the version

python3 -m django --version

Creating A Django Project

Starting a Django project

django-admin startproject _projectroot

After that, change your working directory to _projectroot/ to avoid confusion with the virtualenv folders.

cd _projectroot

This will create the following directories:

├── manage.py
└── template
    ├── asgi.py
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py

Learn what each file does here

Start the development server

python3 manage.py runserver

Upon running the command, the server will run on port 8000 by default (http://127.0.0.1:8000/)

Changing the port is easier: python3 manage.py runserver 8080

A message like the one below shows up but don’t stress out.

You have 17 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.

Creating A Django App

Let’s create a Django app

(Note that there is a difference between a project and an app. An app is like the building blocks of a project.)

python3 manage.py startapp myapp

a new directory called “polls” will be created:

myapp/
    migrations/
        __init__.py
    __init__.py
    admin.py
    apps.py
    models.py
    tests.py
    views.py

Now that forms the skeleton of a simple Django application.