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
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
mysite/ (your folder)
manage.py
mysite/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py| File | What it does |
|---|---|
manage.py | A command tool to run the server, make apps and more |
settings.py | All settings: apps, database, time zone, static files |
urls.py | The main list of URL patterns |
wsgi.py / asgi.py | Entry points used by web servers in production |
__init__.py | Marks the folder as a Python package |
Run the Development Server
Example
python manage.py runserverWatching 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
| Command | What it does |
|---|---|
runserver | Starts the development server |
runserver 8080 | Uses port 8080 instead of 8000 |
startapp name | Creates a new app |
makemigrations | Prepares database changes from your models |
migrate | Applies those changes to the database |
createsuperuser | Creates an admin user |
shell | Opens a Python shell with your project loaded |
Important Settings
Open mysite/settings.py. A few settings you will change often:
Example
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 = Trueshows detailed error pages. Always set it toFalseon a live website.ALLOWED_HOSTSlists the domain names your site may serve, such as["example.com"].INSTALLED_APPSlists 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
import os
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "dev-only-key")Exercise
Exercise
Which command starts Django's development server?
