IDRASAcademic OS
Unit 1: Full-Stack Web Architecture & Django Framework Internals 35 mins study timeINTERMEDIATE

Django MVT Architecture, WSGI/ASGI Pipeline & Request-Response Lifecycle

Deep architectural dissection of how Django processes incoming HTTP requests through WSGI handlers, middleware pipelines, URL resolvers, views, and templates.

Verified: Faculty Peer Review Board

Learning Objectives

    Essential Prerequisites

      Layer 1: Intuition & Why It Matters

      The Core Mental Model

      “Django ko samjhne ke liye ek Restaurant ka example lijiye: 1. Customer (Browser) aata hai aur Menu card dekh kar Order deta hai (HTTP Request). 2. Waiter (URL Dispatcher) order leta hai aur check karta hai ki kaun se Chef (View) ke paas jana hai. 3. Chef (View) order dekhta hai. Agar khana banana hai to Storeroom (Model / Database ORM) se ingredients lata hai. 4. Ingredients prepare karke Chef Plate ko sajata hai (Template) aur Customer ko serve karta hai (HTTP Response). Django me: - Model: Database ka structure (table, columns, constraints). - View: Business logic (data lana, calculate karna, permission check karna). - Template: HTML presentation layer jo user ko dikhta hai.”

      Why This Exists

      Instagram, Pinterest, aur Coursera jaise giant platforms Django par chale hain. Request lifecycle samajhne se security flaws (CSRF, unauthorized access) aur slow database queries diagnose karna aasaan ho jata hai.

      Beginner Foundation

      Django ko samjhne ke liye ek Restaurant ka example lijiye: 1. Customer (Browser) aata hai aur Menu card dekh kar Order deta hai (HTTP Request). 2. Waiter (URL Dispatcher) order leta hai aur check karta hai ki kaun se Chef (View) ke paas jana hai. 3. Chef (View) order dekhta hai. Agar khana banana h...

      Micro Concepts Decomposition

      Layer 3 & 4: Formal Specification & Mechanism

      Hardware State Machine Architecture

      Django's Request-Response Execution Pipeline: 1. The web server (e.g. Nginx via Gunicorn) passes the WSGI environ dictionary to WSGIHandler.__call__(). 2. An instance of WSGIRequest is constructed, initializing request.GET, request.POST, and headers. 3. The request passes through the configured MIDDLEWARE chain in forward order: - SecurityMiddleware -> SessionMiddleware -> CommonMiddleware -> CsrfViewMiddleware -> AuthenticationMiddleware. 4. The URL resolver matches request.path against urlpatterns using compiled regular expressions or path converters. 5. The matching view callable is invoked with (request, *args, **kwargs). 6. The view queries the database via Model.objects.filter() (Django QuerySet evaluation is lazy and transactional). 7. An HttpResponse (or TemplateResponse rendered with Context) is returned. 8. The response passes through the middleware chain in reverse order for compression, cache headers, and cookie injection.
      1. Client initiates TCP handshake and sends HTTP GET request. 2. Nginx terminates SSL/TLS and proxies reverse-request to Gunicorn WSGI socket. 3. WSGIHandler creates request object and executes middleware. 4. View executes ORM query and renders HTML/JSON. 5. Byte stream sent over socket back to client.
      Layer 7: Interactive Laboratory

      Interactive Simulator

      COA • LABDirect Memory Access (DMA) & Cycle Stealing Laboratory
      Launch Fullscreen Lab
      COA • SYSTEM BUS & INTERCONNECTMulti-Master Bus Arbitration

      Bus Arbitration Protocols & Priority Resolution Laboratory

      Bus Master Devices (Click to Toggle Bus Request BR)Priority Order: Device 1 > Device 2 > Device 3
      Master Device 1IDLE
      Priority: Rank #1
      Master Device 2BUS GRANTED
      Priority: Rank #2
      Master Device 3REQUESTING
      Priority: Rank #3
      Signal Wire Topology & Bus Controller State:DAISY CHAINING
      [Bus Controller] ---BG Line---> [Device 1] ---BG Line---> [Device 2] ---BG Line---> [Device 3]
      Common Bus Request Line (BR): HIGH (Asserted)
      Bus Busy Line (BBSY): HIGH (Occupied by Device 2)
      Engineering Tradeoffs:

      Daisy Chaining: Lowest hardware cost (requires only 3 control lines regardless of master count). However, propagation delay is proportional to device count ($O(n)$), and any device failure in the chain breaks grant transmission down the line.

      Layer 5: Step-by-Step Worked Numerical Example

      End-to-End Execution Trace

      Creating a Book Model in Django: ```python from django.db import models class Book(models.Model): title = models.CharField(max_length=255) isbn = models.CharField(max_length=13, unique=True) pages = models.PositiveIntegerField() created_at = models.DateTimeField(auto_now_add=True) def __str__(self): return self.title ``` Running `python manage.py makemigrations` creates migration files, and `migrate` executes `CREATE TABLE` in the database.
      Layer 6: Active Runtime CodeLab

      Step-by-Step Code Execution (PYTHON)

      SQL Studio
      Font
      main.pyGlacier Light
      Ln 1 • Python 3.12
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      295 chars • 12 lines • Ln 1UTF-8 • 4 Spaces
      Interactive Terminal Shell

      Sandbox Terminal Ready

      Click Run Code or press Ctrl+Enter to compile and execute.

      ⚡ AURXON Bitstream Runtime v4.8IDRAS Academic Virtual Node
      Layer 8: Practice & Knowledge Verification

      Active Assessment Quiz

      No Practice Questions Configured

      Questions for this topic are currently undergoing faculty review.

      Academic Evaluation Preparation

      Viva Examination & University Scoring Strategy

      Standard Viva Examination Questions

      How to Write High-Scoring University Exam Answers

      Draw the complete architectural diagram showing Browser -> Web Server -> WSGI -> Middleware -> URL Conf -> View -> Model/DB & Template -> Response. Detail each component's responsibility, and write a concrete model and view snippet with comments.