Django Tutorial menu

Django Project

A Django project is the whole website: its settings, its main URLs and all its apps.

Create a Project

With your virtual environment active, run:

Example

bash
django-admin startproject mysite .

The dot . at the end means "create it in the current folder", so you do not get an extra folder level.

The Project Files

Example

text
mysite/            (your folder)
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py
FileWhat it does
manage.pyA command tool to run the server, make apps and more
settings.pyAll settings: apps, database, time zone, static files
urls.pyThe main list of URL patterns
wsgi.py / asgi.pyEntry points used by web servers in production
__init__.pyMarks the folder as a Python package

Run the Development Server

Example

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

System check identified no issues (0 silenced).
October 15, 2026 - 10:30:00
Django version 5.2.7, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Open http://127.0.0.1:8000/ and you will see Django's welcome page with a rocket. The server restarts by itself when you save a Python file.

You may see a message about "unapplied migrations". That is normal; you will fix it in the models lesson.

The runserver command is only for development on your computer. Real websites use a production server such as Gunicorn.

Useful manage.py Commands

CommandWhat it does
runserverStarts the development server
runserver 8080Uses port 8080 instead of 8000
startapp nameCreates a new app
makemigrationsPrepares database changes from your models
migrateApplies those changes to the database
createsuperuserCreates an admin user
shellOpens a Python shell with your project loaded

Important Settings

Open mysite/settings.py. A few settings you will change often:

Example

python
DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
]

LANGUAGE_CODE = "en-us"
TIME_ZONE = "Asia/Karachi"
  • DEBUG = True shows detailed error pages. Always set it to False on a live website.
  • ALLOWED_HOSTS lists the domain names your site may serve, such as ["example.com"].
  • INSTALLED_APPS lists every app the project uses, including your own.
  • TIME_ZONE = "Asia/Karachi" makes dates show in Pakistan time.

The Secret Key

settings.py also contains a SECRET_KEY. Django uses it to sign sessions and security tokens. Never share it or upload it to a public GitHub repository. In real projects, read it from an environment variable:

Example

python
import os

SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "dev-only-key")

Exercise

Exercise

Which command starts Django's development server?

Learn Django with a teacher

Join the Full Stack Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp