Design Principles: Models, Views & Templates

  • An important design pattern, that’s at the core of every site built on Django has three types of components:
    • Models: A model tells Django how to work with data that will be stored in the app. Code-wise, a model is just a class, it has attributes and methods, just like another class.
    • Templates: Generates HTML (presentation logic only)
    • Views: Takes a request parameter and returns a response object
      • Example:

Diagram showing Django's MVT flow: browser sends a request to a URL, the View processes it using the Model and Template, and returns a response


More on Models and Migrations:

Diagram explaining Django models and migrations showing the relationship between models.py, the database schema, and migration files