What Is Django
Introduction
Django is a high-level Python web framework for building full-stack applications quickly. It ships with an ORM, admin interface, user authentication, form handling, template engine, and database migrations—so you spend less time wiring infrastructure and more time on product features. This chapter explains what Django is, how its MTV pattern maps to familiar MVC ideas, and how this track fits alongside the Python, MySQL, and Nginx courses on Hello Code.
Prerequisites
- Basic Python (functions, classes, modules, exceptions)
- Idea of HTTP (browser requests a URL, server returns HTML or JSON)
- No Django installation required yet for this overview
- Helpful: pip and virtual environments concepts
Django in One Sentence
Django is a batteries-included web framework that maps URLs to Python views, loads data through models, and renders HTML templates—or JSON for APIs—while managing users, forms, and database schema changes for you.
Teams typically use Django for:
| Use case | What Django provides |
|---|---|
| Content sites & blogs | Models, templates, pagination, admin for editors |
| Internal tools | Admin + auth + forms with little custom UI code |
| REST APIs | Views + Django REST framework (covered later) |
| Multi-app products | Project + multiple Apps (users, shop, blog) in one codebase |
This track uses Django 5.x and Python 3.10+, with SQLite for local development and MySQL for production-style deploys. The full 31-chapter outline is in the Django Chapter Index.
A Typical Request Path
Browser Django Your code
│ │ │
│ GET /posts/3/ │ │
├──────────────────────►│ URLconf → view │
│ ├─────────────────────────────►│
│ │ Model (ORM) → DB │
│ │◄─────────────────────────────┤
│ │ render template │
│◄──────────────────────┤ HTML or JsonResponse │
│ 200 OK │ │Code explanation:
- URLconf (
urls.py) matches the path and calls a view function or class - The view may read/write data via Models (ORM)
- HTML responses use Templates; APIs return JSON
- Middleware runs before/after the view (security, sessions, auth)
MTV vs MVC
Django documentation uses MTV (Model–Template–View). It aligns with MVC (Model–View–Controller) like this:
| MTV (Django) | MVC (general) | Role |
|---|---|---|
| Model | Model | Data structure and database access |
| Template | View (presentation) | HTML (or partial UI) |
| View | Controller | Request handling, business logic |
Code explanation:
- In Django, the word “view” means controller logic—not the visual page
- The visual page is the template
- Naming differs from Rails or Spring MVC; the flow is the same idea
Batteries Included
Unlike minimal frameworks, Django defaults include:
| Built-in piece | Purpose |
|---|---|
| ORM | Define models in Python; avoid raw SQL for CRUD |
| Migrations | makemigrations / migrate evolve schema in Git |
| Admin | /admin/ CRUD UI for staff ( huge time-saver ) |
| Auth | Users, groups, permissions, login sessions |
| Forms | Validation, CSRF protection, ModelForm |
| Templates | Django Template Language (DTL) |
| Security helpers | CSRF, clickjacking, SQL injection resistance via ORM |
You can replace pieces (e.g. use DRF for APIs only), but the defaults are production-proven.
Tip
Learn Python First
Django is still Python. If loops, functions, and classes are shaky, solidify them in the Python track before deep Django chapters.
Django vs Flask vs FastAPI
| Django | Flask | FastAPI | |
|---|---|---|---|
| Style | Full-stack, opinionated | Microframework, you assemble | Async API-first |
| ORM | Built-in | Flask-SQLAlchemy (add-on) | SQLAlchemy / others (add-on) |
| Admin | Built-in | Build yourself | N/A |
| Best for | Sites + admin + APIs in one project | Small APIs, custom stacks | High-performance async APIs |
| Hello Code track | This series | gen_article_plan/flask.md (planned) | Mentioned only for comparison |
Choose Django when you want one coherent stack for HTML pages, staff admin, and database-backed features. Choose Flask when you want maximum flexibility with fewer defaults. Choose FastAPI when async and OpenAPI-first APIs are the main goal.
WSGI and ASGI (Concept)
Python web apps expose an application object that a server calls:
| Interface | Server examples | Django usage |
|---|---|---|
| WSGI | Gunicorn, uWSGI | Default sync deploy; most tutorials |
| ASGI | Uvicorn, Daphne | Async views, WebSockets, Channels |
Code explanation:
- Development:
python manage.py runserver(convenient, not for production) - Production: Gunicorn + Nginx reverse proxy (covered later)
- You write Django; the server speaks HTTP to the world
Project vs Application
Django splits code into:
myshop/ ← Project (one website / deployment unit)
├── config/ ← settings, root urls
├── blog/ ← App (reusable module)
├── shop/ ← App
└── manage.py| Term | Meaning |
|---|---|
| Project | Configuration container: settings.py, root urls.py, WSGI/ASGI |
| App | Feature module: models, views, urls for one area (blog, users) |
One project hosts many apps. Apps can be reused across projects or published as packages.
Comparison for Java Developers
If you know Spring Boot:
| Spring Boot | Django |
|---|---|
@RestController / @Controller | Views (FBV/CBV) |
application.yml | settings.py |
| JPA / Hibernate | Django ORM |
| Flyway / Liquibase | Migrations |
| Spring Security | django.contrib.auth + middleware |
| Thymeleaf / JSP | Django templates |
| Executable JAR + embedded Tomcat | Gunicorn + Nginx (typical) |
Both aim to ship web backends quickly; Django is the Python ecosystem default for full-stack sites.
What Django Is Not
- Not a separate language — you write Python
- Not a frontend framework — use templates for server HTML, or pair with React/Vue for SPA + Django API
- Not only for small sites — Instagram, Mozilla, and many SaaS products started on or still use Django patterns
- Not the only Python web option — Flask and FastAPI are valid; Django trades flexibility for speed of development
How This Track Is Organized
This series follows frontend/gen_article_plan/django.md:
| Section | Topics |
|---|---|
| Environment & first project | venv, install, startproject, runserver |
| Structure & settings | Project/App, settings.py, multi-environment |
| URLs & views | URLconf, FBV, class-based views |
| Templates & static | DTL, inheritance, {% static %} |
| Models & migrations | ORM, QuerySet, Admin |
| Forms & auth | ModelForm, CSRF, login, permissions |
| Testing & API | TestCase, Django REST framework intro |
| Deploy & projects | Gunicorn, Nginx, MySQL, four hands-on projects |
Related Hello Code paths:
- Python — language fundamentals
- MySQL — production database
- Git — version control and CI
- Nginx — reverse proxy and HTTPS
- Spring Boot — Java full-stack comparison
- Vue — SPA frontend for DRF APIs (REST auth & CORS ↔ Vue 17, blog reader project)
Mini Preview: What You Will Run
You do not need to run this yet—it shows the shape of a minimal view:
# blog/views.py
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello Django")# config/urls.py
from django.urls import path
from blog import views
urlpatterns = [
path("", views.home),
]Then:
python manage.py runserver
# open http://127.0.0.1:8000/Later chapters replace plain HttpResponse with templates, models, and the admin.
FAQ
Is Django good for beginners?
Yes, if you already know Python basics. Django has many concepts at once (urls, views, models)—the track introduces them step by step.
Django vs Flask—which should I learn first?
Learn Django for full-stack sites with admin and ORM in one place. Learn Flask for minimal APIs and maximum control. Hello Code teaches Django as the primary Python full-stack path.
Do I need to know SQL?
Helpful but not required at first—the ORM covers most CRUD. MySQL SQL helps for reporting, tuning, and debugging.
Can Django build JSON APIs only?
Yes. Many teams use Django + DRF without server-rendered HTML. This track teaches MTV first, then API chapters.
Which Python version?
3.10+ recommended; match your Python install docs.
Is Django async?
Django 4+ supports async views and ASGI; this track focuses on sync WSGI deploy first—the common path on VPS and tutorials.
Django 4 vs 5?
Use Django 5.x for new projects; examples assume current LTS-style releases from djangoproject.com.
Where does React/Vue fit?
Django serves API + auth; the browser UI can be a separate SPA. Nginx serves static build files and proxies /api/ to Django—patterns in later chapters and the Nginx SPA project.