From the course: Introduction to Django

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Views

Views

- Okay, so let's start looking at views. And here's just a very simple view function that you could have. And it takes in a request and returns a response or HTTP request and HTTP response. So when a URL pass gets matched, then Django calls the corresponding view function. It passes in the request as well as any captured arguments from the URL. And the view function might return some HTML or JSON data or an exception page or other things like a file. You can also handle, GET and POST request differently and update or retrieve data from the database via models. And you can also require certain permissions from the user. So there's a lot of things that the view can be, the logic that can be in the view and the things that it manages and controls. But at the end of the day, it takes in a request and returns a response. An HTTP request will have a user attached to it as long as you're using some sort of middleware like the default Django auth middleware. And the user will just be an…

Contents