0Pricing
Django Academy · Lesson

Mixins and as_view()

Compose behavior and wire CBVs into urls.

What as_view Really Does

A class cannot be a URL target on its own. as_view() returns a function that creates an instance and dispatches the request.

Always Call as_view in urls

In urls, you call the class with as_view(), never the bare class. That callable is what Django actually routes to.

path("", HomeView.as_view())

All lessons in this course

  1. From Function Views to View Classes
  2. TemplateView and get_context_data
  3. Handling get and post Methods
  4. Mixins and as_view()
← Back to Django Academy