---
source: https://iinventedlight.com/library/notes/django-class-based-views.md
title: "Django class-based views: as_view and dispatch"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Django docs); BSD-3-Clause (Django); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Django docs, Introduction to class-based views; Django, intro.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: django class-based views"
tags: [django, views, as_view, dispatch, generic]
client: Librarian
sources:
  - id: S1
    title: "Introduction to class-based views"
    publisher: Django docs
    url: https://docs.djangoproject.com/en/5.2/topics/class-based-views/intro/
    accessed: 2026-11-18
    license: "BSD-3-Clause"
  - id: S2
    title: "intro.txt"
    publisher: Django
    url: https://raw.githubusercontent.com/django/django/stable/5.2.x/docs/topics/class-based-views/intro.txt
    accessed: 2026-11-18
    license: "BSD-3-Clause"
---
# Django class-based views: as_view and dispatch
**Answer:** Class-based views let you implement a view as a Python object rather than as a function, without replacing function-based views. as_view is a class method that returns a callable for the URL pattern. dispatch inspects whether the request is GET or POST and then relays it to a matching method.

## Examples

```python
from django.urls import path
from django.views.generic import TemplateView

urlpatterns = [
    path("about/", TemplateView.as_view(template_name="about.html")),
]
```

## Notes

TemplateView uses the dispatch behavior defined in the View base class. Mixins (multiple inheritance) can be used to factor code into reusable components. Code related to specific HTTP methods can be addressed by separate methods, not by conditional branching.

## Reference list

- `Class-based` views implement views as Python objects instead of functions.
- `Mixins` can factor code into reusable components.
- `Class-based` views are an alternative to function-based views.

## See also

- [django-views](https://iinventedlight.com/library/notes/django-views/)
- [django-request-response](https://iinventedlight.com/library/notes/django-request-response/)
- [django-forms](https://iinventedlight.com/library/notes/django-forms/)

## Claims

- id: C1
  claim: Class-based views implement views as Python objects instead of functions.
  source: S1
  evidence: "They do not replace function-based views, but"

- id: C2
  claim: Mixins can factor code into reusable components.
  source: S2
  evidence: "used to factor code into reusable components"

- id: C3
  claim: Class-based views are an alternative to function-based views.
  source: S2
  evidence: "Class-based views provide an alternative way to implement views as Python"

## Sources

- [S1] Introduction to class-based views. Django docs. https://docs.djangoproject.com/en/5.2/topics/class-based-views/intro/ . License: BSD-3-Clause. Accessed 2026-11-18.

- [S2] intro.txt. Django. https://raw.githubusercontent.com/django/django/stable/5.2.x/docs/topics/class-based-views/intro.txt . License: BSD-3-Clause. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Django docs, Introduction to class-based views; Django, intro.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
