Class-Based Views
The view functions, you have seen earlier, involve a lot of coding effort.
For responses that need a static page or a listing page, Django provides class-based views.
Using class-based views,
- Code organization is better.
- Specific HTTP methods like GET and POST can be addressed.
- Easy to build reusable components.
- No need to use render, redirect functions to send an HTTP response.
Let's consider a sample static content page written in static.html
file.
Using a class-based view TemplateView
, the template can be called as shown.
from django.views.generic import TemplateView
class StaticView(TemplateView):
template_name = "static.html"
No comments:
Post a Comment
If you have any doubts, Please let us know.