O'Reilly logo

Learning Python Design Patterns by Gennadiy Zlobin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Controller – the glue between the model and view

The direct responsibility of the controllers is to receive data from the request and send it to other parts of the system. Only in this case, the controller is "thin" and is intended only as a bridge (glue layer) between the individual components of the system.

Let's look at the following recommendations for working with controllers:

  • Strive to perform the following in controllers:
    • Pass data from user requests to the model for processing, retrieving and saving the data
    • Pass data to views for rendering
    • Handle all request errors and errors from models
  • Avoid the following in controllers:
    • Render data
    • Work with the database and business logic directly

Thus, in one statement:

We need smart models, thin controllers, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required