Search code examples
djangodjango-modelsviewdjango-views

What is the differnce between templateview and detailview in django?


Each of this is for displaying a single template as we want,then what is actually it's difference which make it differ? And which is better for using and Why?


Solution

  • TemplateView: Just a simple view to render an HTML template with provided context data.

    DetailView: Generic view that works on a model object, expect a lookup kwarg in URL or get_object() can be overridden to return a single model object. and then pass that object in context data to be used in the template.