Topics in this subject
Django 3 min read Updated 11 Aug 2026

Mental Model and MVT

Batteries included, Project vs App, and the Model-View-Template architecture.

🧑‍🏫 Sabse pehle — simple mein samjho#

Express (Node) ya FastAPI mein tumhe sab kuch manually setup karna padta hai — DB connect karo, auth banao, folder structure socho. Django ek "Batteries Included" framework hai. Iska matlab hai jab tum Django start karte ho, toh ye tumhe pehle se hi Admin panel, Authentication, Database ORM, aur proper folder structure bana kar de deta hai. Tumhara focus sirf features banane pe hota hai. Django MVT (Model-View-Template) pattern follow karta hai. Model (Database), View (Logic/Controller), Template (HTML/Frontend).

1. Batteries Included#

Django's core philosophy is to provide everything a typical web application needs right out of the box, reducing decision fatigue.

  • Built-in Admin Panel: You get a fully functional CMS for your database instantly.
  • Built-in ORM: No need to install separate packages (like Prisma or SQLAlchemy).
  • Built-in Auth: Complete user management (login, logout, password resets).
  • Security by Default: Automatic protection against CSRF, Clickjacking, and SQL Injection.

2. Project vs. Apps#

The most confusing part of Django for beginners is its file structure. Django divides logic into a Project and multiple Apps.

  • The Project: This is the entire website and its global configuration (settings, database connections, main URL routing).
  • The App: A self-contained module that performs a specific function. A single project is made up of multiple apps.

For example, if you are building an E-commerce site:

  • Project: ecommerce_store (handles global settings)
  • App 1: users (handles login/registration)
  • App 2: products (handles catalog and inventory)
  • App 3: cart (handles checkout)
# 1. Create the main project
django-admin startproject myproject

# 2. Create a specific app inside it
python manage.py startapp blog

Crucial Step: After creating an app, you MUST register it in the INSTALLED_APPS list inside myproject/settings.py!

3. The MVT Architecture#

Most frameworks follow MVC (Model-View-Controller). Django follows MVT (Model-View-Template). It is essentially the same concept, just named differently.

  1. Model (models.py): The data access layer. You define Python classes, and Django translates them into database tables.
  2. View (views.py): The business logic layer (The "Controller" in MVC). It receives the HTTP request, asks the Model for data, and passes that data to a Template (or serializes it as JSON).
  3. Template (templates/): The presentation layer (The "View" in MVC). HTML files with special Django template tags to inject dynamic Python data.

The Request Flow#

  1. User requests a URL (e.g., /articles/1/).
  2. Django checks urls.py to match the URL to a specific View function.
  3. The View asks the Model to fetch Article #1 from the database.
  4. The Model returns the data to the View.
  5. The View passes this data into a Template (article.html).
  6. The compiled HTML is sent back to the user's browser.