liveBook · Manning

Controller

As explained in Django in Action

The MVC controller is the component responsible for handling interactions with application data and coordinating application behavior.

A controller is the input-and-control part of the MVC pattern: it connects user interactions with models and views. This matters when a site grows beyond static files and must handle data, comments, uploads, and application behavior. section 1.1.1

Django uses MVC as a useful mental model rather than a strict blueprint. Its view handles Python request-processing code, so the boundary between Django’s view and controller remains deliberately fuzzy. section 1.1.1 section 1.3

A typical request path looks like this:

  • A web server passes the URL request to Django through WSGI. section 1.1.1
  • Django checks urls.py and its urlpatterns list of path objects. section 1.1.1
  • A path selects a Django view, implemented as a function or class that receives the request and returns a response document. section 1.1.1 section 1.3
Figure 1.4 Model—view—controller architectural pattern
figure

Use the MVC diagram to distinguish the controller’s interaction role from the model’s data and business logic and the view’s presentation role. section 1.1.1

How Django in Action covers it

How deep it goes
Defines the controller and traces URL routing to views, while stopping short of prescribing a separate Django controller component.
Examples
Uses static-versus-dynamic websites, urls.py, urlpatterns, path objects, Django views, and request-response handling.
What you can do after
Understand how Django routes a browser request and where controller responsibilities appear within its view-centered architecture.
How it connects
Connects MVC with models, views, URL routing, templates, HTTP requests, and single-page applications.

Also explained in

Compare how 8 books explain controller →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.