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 caseWhat Django provides
Content sites & blogsModels, templates, pagination, admin for editors
Internal toolsAdmin + auth + forms with little custom UI code
REST APIsViews + Django REST framework (covered later)
Multi-app productsProject + 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

text
  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
ModelModelData structure and database access
TemplateView (presentation)HTML (or partial UI)
ViewControllerRequest 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 piecePurpose
ORMDefine models in Python; avoid raw SQL for CRUD
Migrationsmakemigrations / migrate evolve schema in Git
Admin/admin/ CRUD UI for staff ( huge time-saver )
AuthUsers, groups, permissions, login sessions
FormsValidation, CSRF protection, ModelForm
TemplatesDjango Template Language (DTL)
Security helpersCSRF, 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

DjangoFlaskFastAPI
StyleFull-stack, opinionatedMicroframework, you assembleAsync API-first
ORMBuilt-inFlask-SQLAlchemy (add-on)SQLAlchemy / others (add-on)
AdminBuilt-inBuild yourselfN/A
Best forSites + admin + APIs in one projectSmall APIs, custom stacksHigh-performance async APIs
Hello Code trackThis seriesgen_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:

InterfaceServer examplesDjango usage
WSGIGunicorn, uWSGIDefault sync deploy; most tutorials
ASGIUvicorn, DaphneAsync 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:

text
myshop/                    ← Project (one website / deployment unit)
├── config/                ← settings, root urls
├── blog/                  ← App (reusable module)
├── shop/                  ← App
└── manage.py
TermMeaning
ProjectConfiguration container: settings.py, root urls.py, WSGI/ASGI
AppFeature 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 BootDjango
@RestController / @ControllerViews (FBV/CBV)
application.ymlsettings.py
JPA / HibernateDjango ORM
Flyway / LiquibaseMigrations
Spring Securitydjango.contrib.auth + middleware
Thymeleaf / JSPDjango templates
Executable JAR + embedded TomcatGunicorn + 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:

SectionTopics
Environment & first projectvenv, install, startproject, runserver
Structure & settingsProject/App, settings.py, multi-environment
URLs & viewsURLconf, FBV, class-based views
Templates & staticDTL, inheritance, {% static %}
Models & migrationsORM, QuerySet, Admin
Forms & authModelForm, CSRF, login, permissions
Testing & APITestCase, Django REST framework intro
Deploy & projectsGunicorn, Nginx, MySQL, four hands-on projects

Related Hello Code paths:

Mini Preview: What You Will Run

You do not need to run this yet—it shows the shape of a minimal view:

python
# blog/views.py
from django.http import HttpResponse
 
def home(request):
    return HttpResponse("Hello Django")
python
# config/urls.py
from django.urls import path
from blog import views
 
urlpatterns = [
    path("", views.home),
]

Then:

bash
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.