When should you use Django's built-in Generic Views like ListView or DetailView versus writing a custom view from scratch?
Last updated
Use generic views like
ListView/DetailViewfor standard patterns. They handle pagination, object lookup, and template selection, and light tweaks fit hooks likeget_queryset()orget_context_data().Write a custom view when the flow spans multiple models, branches conditionally, or has side effects, or when you'd override so many methods the generic base obscures the logic.
Rule of thumb: start generic and switch once fighting the framework costs more than the boilerplate it saves.
- https://docs.djangoproject.com/en/6.0/topics/class-based-views/generic-display/
- https://dev.to/victoria/writing-efficient-django-gol
- https://www.geeksforgeeks.org/python/class-based-vs-function-based-views-which-one-is-better-to-use-in-django/
- https://dev.to/hernanchilabert/understanding-django-rest-framework-apiview-vs-genericviewset-2927