What is the best way to manage django request types?

Viewed 42

Is there any way to manage request types in django (GET, POST,...) except of 'if' condition?
Django documents usually manage requests with a if condition inside of view functions. but i am looking for something to do not allow requests enter to my view function if the request was not 'GET' type.

Is there any decorator to manage request like flask or manage request types in the url.py?

1 Answers

Usage in your URLconf
The most direct way to use generic views is to create them directly in your URLconf. If you’re only changing a few attributes on a class-based view, you can pass them into the as_view() method call itself:

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

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