The View base class and dispatch()
coreintermediateEvery class-based view subclasses View, whose as_view() returns a plain function Django can call like any FBV. dispatch() is what that function actually runs — it looks at request.method and calls the matching method (get(), post(), ...) on the instance.
Think of it as
as_view() is a small factory that hands urls.py an ordinary function, hiding the class entirely — from the URLconf's perspective, a CBV looks exactly like an FBV. Once called, that function creates an instance and hands control to dispatch(), which is a receptionist checking request.method against a name tag (get, post, put...) and routing the call to whichever method matches — or to http_method_not_allowed if none does.
What we're doing: Write a minimal CBV directly on View, with distinct GET and POST handling, and see what happens when a method is missing.
- 3
- get() handles displaying the login form; dispatch() routes here for any GET request to this URL.
- 6
- No put()/delete() are defined on this class, so dispatch() sends those methods to http_method_not_allowed() automatically — no manual check required, unlike an FBV.
Why this works: A CBV gets its HTTP-method dispatch for free from the base class, unlike an FBV, where every method check has to be written by hand — this is the core reason CBVs help: request.method routing is a solved problem the moment a view class defines get()/post() as separate methods.
Forgetting to call .as_view() when registering a CBV in urls.py
Wrong
Better
What you see: TypeError: view must be a callable or a list/tuple in the case of include() — Django expects a function, not a class.
Why: .as_view() is what converts the class into the plain function urls.py needs — the class itself is never a valid view; it is a blueprint as_view() uses to build one instance per request.
- urlpatterns — MyView.as_view()
- leads to dispatch()
- dispatch() — checks request.method
- leads to self.get() / self.post()
- self.get() / self.post()
What as_view() and dispatch() actually do
Together
Remember: MyView.as_view() returns a function urls.py can call; dispatch() (inherited, not written by hand) routes to get()/post()/etc. based on request.method — a missing method becomes an automatic 405.
See also: views · mixins and mro · http methods

