What Django Does
- ORM — define models in Python, auto-generate SQL
- Admin — auto-generated CRUD admin panel
- Auth — users, groups, permissions, sessions, CSRF
- Migrations — schema migrations from model changes
- URL routing — regex and path-based URL dispatcher
- Templates — Django template language (DTL) or Jinja2
- Forms — validation, rendering, model forms
- Middleware — request/response processing pipeline
- Caching — Redis, Memcached, file, DB backends
- Security — XSS, CSRF, SQL injection, clickjacking protections
- Django REST Framework — add-on for building APIs
Architecture
MVT (Model-View-Template): Model is the ORM layer, View handles logic and returns responses, Template renders HTML. WSGI/ASGI compatible — deploy behind Gunicorn, uvicorn, or Daphne. Settings-based configuration via settings.py.
Self-Hosting
# Production
pip install gunicorn
gunicorn mysite.wsgi:application --bind 0.0.0.0:8000 --workers 4
# Docker
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "mysite.wsgi", "--bind", "0.0.0.0:8000"]Key Features
- Batteries-included (ORM, admin, auth, migrations)
- Auto-generated admin panel
- Django REST Framework for APIs
- ASGI support (async views)
- Comprehensive security defaults
- Mature ecosystem (10,000+ packages)
- Excellent documentation
- Huge community
Comparison
| Framework | Language | Philosophy | Best For |
|---|---|---|---|
| Django | Python | Batteries-included | Full apps |
| FastAPI | Python | Async + types | APIs |
| Flask | Python | Micro | Small APIs |
| Rails | Ruby | Convention > config | Full apps |
| Laravel | PHP | Elegant syntax | Full apps |
| Spring Boot | Java | Enterprise | Enterprise |
常见问题 FAQ
Q: Django vs FastAPI? A: Django 是全栈框架(ORM、admin、auth 全包),适合传统 web app + API;FastAPI 专注高性能异步 API,适合纯 API 后端和微服务。
Q: Django 支持 async 吗? A: 支持。Django 4.1+ 支持 async views、middleware、ORM(部分)。完整 async ORM 仍在推进中。
Q: admin 可以生产用吗? A: 内部管理可以。面向用户的后台建议基于 Django admin 定制或用 Django Unfold/Grappelli 等主题。
来源与致谢 Sources
- Docs: https://docs.djangoproject.com
- GitHub: https://github.com/django/django
- License: BSD 3-Clause