Django Basics
10 examples to get you started with Django 5.2 - 7 basic and 3 intermediate.
Search across all documentation pages
10 examples to get you started with Django 5.2 - 7 basic and 3 intermediate.
uv pip install "django>=5.2"
django-admin startproject config .
python manage.py migratepython manage.py runserver for local development.Settings, URLs, and an app module.
# config/urls.py
from django.contrib import admin
from django.urls import path
from hello import views
urlpatterns = [
path("admin/", admin.site.urls),
path("", views.home),
]urls.py.Related: Models & the ORM - database models
Return HTTP responses from Python callables.
from django.http import JsonResponse
def home(request):
return JsonResponse({"message": "Hello, Django"})request first.JsonResponse for simple APIs.Capture path segments.
from django.urls import path
from . import views
urlpatterns = [path("users/<int:user_id>/", views.user_detail)]Configure installed apps and database.
# config/settings.py excerpt
INSTALLED_APPS = ["django.contrib.admin", "hello"]
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "db.sqlite3"}}Built-in CRUD UI for models.
from django.contrib import admin
from .models import Item
admin.site.register(Item)admin.site.ModelAdmin.Related: The Admin - customization
Server-rendered HTML with Django template language.
from django.shortcuts import render
def home(request):
return render(request, "home.html", {"title": "Django"})templates/.Related: Templates & Forms - forms
CLI tasks via manage.py.
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = "Demo command"
def handle(self, *args, **options):
self.stdout.write("ok")management/commands/.Process requests globally.
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
]Related: Caching & Performance - cache middleware
Explicit app initialization.
from django.apps import AppConfig
class HelloConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "hello"default_app_config pattern via AppConfig.Return structured data without DRF.
from django.http import JsonResponse
from django.views.decorators.http import require_GET
@require_GET
def health(request):
return JsonResponse({"status": "ok"})Related: Django REST Framework - viewsets
Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 19, 2026