Django Local Development Guide
Run Python web applications on localhost:8000 using Django, configure SQLite or PostgreSQL databases.
Django is a full-stack web framework for Python, featuring built-in ORM, an admin interface, and an authentication system. For local development, use the runserver command, which defaults to http://localhost:8000.
Default localhost Access
| Purpose | Address |
|---|---|
| Development Server | http://localhost:8000 |
| Admin Interface | http://localhost:8000/admin |
| Specify Port | python manage.py runserver 8080 |
Quick Start
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install django
django-admin startproject mysite
cd mysite
python manage.py migrate
python manage.py runserverDatabase
Default SQLite (zero configuration):
# settings.py default
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}PostgreSQL (recommended for production and complex projects):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': 'localhost',
'PORT': '5432',
'NAME': 'mydb',
'USER': 'postgres',
'PASSWORD': 'secret',
}
}You need to install: pip install psycopg2-binary
Create Superuser
python manage.py createsuperuserAccess http://localhost:8000/admin to log in to the admin interface.
Comparison with FastAPI / Flask
| Framework | Default Port | Features |
|---|---|---|
| Django | 8000 | Full-stack, Admin, ORM integrated |
| Flask | 5000 | Micro-framework, flexible |
| FastAPI | 8000 (Uvicorn) | Asynchronous API first |
Frequently Asked Questions
Port 8000 Occupied
Switch to runserver 8001; or terminate the occupying process (see the port-conflicts article).
Static Files Not Loading
Django handles this automatically in development; for production, use collectstatic + WhiteNoise/Nginx.
ALLOWED_HOSTS
Usually not an issue with local DEBUG=True; set domain names when deploying.
Summary
Run Django locally with python manage.py runserver and access http://localhost:8000; start with SQLite for the database, then switch to PostgreSQL (5432) as needed.