QamoosTech
Web & APIsRouting and viewsBeginnerDjangoPython

View

PronunciationVYOO

Definition

A view is the function (or class) that receives a request and returns a response. It is where you decide what data to fetch and what to send back.

Where you hear it

In Django and Flask code, MVC and MVT discussions, and bug reports that name "the view that handles this URL".

Examples

  • The view loads the circle, then renders the page.
  • Keep business rules out of the view; call a service function.
  • The view checks the user's role before it returns the admin page.

Common mistake

Putting all the logic in the view. It becomes huge and hard to test; move rules into separate functions.

Don't confuse with

A template, which only describes how the page looks. The view decides what data the page gets.

Say it at work

  • In a meeting or chatWhich view serves this URL?
  • In an email or ticketThe view returns a 404 when the circle doesn't exist.