Learn Django

Understanding Django Views

Django views are a key component of applications built with the framework. At their simplest they are a Python function or class that takes a web request and return a web response. Views are used to do things like fetch objects from the database, modify those objects if needed, render forms, return HTML, and much more.

Class Based Views vs. Function Based Views

Django has two types of views; function-based views (FBVs), and class-based views (CBVs). Django originally started out with only FBVs, but then added CBVs as a way to templatize functionality so that you didn't have to write boilerplate (i.e. the same code) code over and over again. CBVs would be a way to increase productivity and make it so that you don't have to write as much code!

At their core, CBVs are Python classes. Django ships with a variety of "template" CBVs that have pre-configured functionality that you can reuse and oftentimes extend. These classes are then given helpful names that describe what kind of functionality they provide. You'll often see these referred to as "generic views" because they provide solutions to common requirements. The classes have documentation on Django's project site that shows what functionality is offered, what settings are required or possible, and how to extend them.

This project uses a mix of CBVs and FBVs to give you experience with both. The home page is built using a CBV.

Track your progress with a free account