![]() |
VOOZH | about |
Django provides several class based generic views to accomplish common tasks. The simplest among them is TemplateView. It Renders a given template, with the context containing parameters captured in the URL.
TemplateView should be used when you want to present some information on an HTML page. TemplateView shouldn’t be used when your page has forms and does creation or update of objects. In such cases, FormView, CreateView, or UpdateView is a better option.
TemplateView is most suitable in the following cases:
Explanation :
Illustration of How to use TemplateView using an Example. Consider a project named geeksforgeeks having an app named geeks.
Refer to the following articles to check how to create a project and an app in Django.
Let’s write a view using base class view View and then modify it to use TemplateView. TemplateView would help us avoid several lines of code.
Python manage.py makemigrations Python manage.py migrate Python manage.py runserver