Django CBV Method Cheat Sheet

 

Django class-based views inherit functionality from several mixins, which can make it difficult to quickly identify the most relevant attributes and hooks.
This cheat sheet summarizes the most commonly used ones for quick reference.

 

Jump to:

 

 

🔗View🔝

View is the base class for all Django class-based views.
It provides the core request dispatching mechanism that routes HTTP requests to the appropriate handler method (get, post, etc.).

Common attributes

http_method_names
view_is_async

Most useful hooks

dispatch()
get()
post()
http_method_not_allowed()


 

 

 

🔗CreateView 🔝

CreateView is mostly about handling form submission and saving a new object.
In practice, form_valid() is often where the real customization happens.

Common attributes

model
form_class
fields
template_name
success_url

Most useful hooks

dispatch()
get_form_kwargs()
get_context_data()
form_valid()
get_success_url()


 

 

 

🔗ListView🔝

ListView is mainly about controlling which objects are shown and how they are displayed.
get_queryset() is by far the most important method here.

Common attributes

model
queryset
template_name
context_object_name
paginate_by
ordering

Most useful hooks

get_queryset()
get_context_data()
paginate_queryset()


 

 

 

🔗UpdateView🔝

UpdateView behaves similarly to CreateView, but works with an existing object.
In most real projects, these are the methods you’ll override most often.

Common attributes

model
form_class
fields
template_name
success_url

Most useful hooks

get_form_kwargs()
form_valid()
get_success_url()


 

 

 

🔗DeleteView🔝

DeleteView is usually simple.
You often only need to decide where to redirect after deletion and optionally restrict access.

Common attributes

model
template_name
success_url
context_object_name

Most useful hooks

get_success_url()
dispatch()


 

 

 

🔗DetailView🔝

DetailView is straightforward: fetch one object and render it.
get_object() is useful when you need custom lookup logic, and get_context_data() lets you enrich the template.

Common attributes

model
queryset
template_name
context_object_name
pk_url_kwarg
slug_field
slug_url_kwarg

Most useful hooks

get_object()
get_context_data()


 

 

 

🔗TemplateView🔝

TemplateView is probably the simplest CBV.
Most of the time, the only customization you need is adding extra context for the template.

Common attributes

template_name
extra_context

Most useful hooks

get_context_data()


 

 

 

🔗FormView🔝

FormView is useful when you need form handling without directly creating or updating a model instance.
These hooks cover almost all practical customizations.

Common attributes

form_class
template_name
success_url
initial

Most useful hooks

get_form_kwargs()
form_valid()
form_invalid()
get_success_url()


 

 

 

🔗RedirectView🔝

RedirectView is mostly about deciding where the user should be sent.
get_redirect_url() is the key method, and dispatch() can be helpful for conditional redirect logic.

Common attributes

url
pattern_name
permanent
query_string

Most useful hooks

get_redirect_url()
dispatch()

 

 

Official Django documentation