from django.views.decorators.http import require_http_mothods
@require_http_methods(["GET", "POST"])
def my_view(request):
pass
There is a "@" in above example. But I could not figure out that. Thanks in advance. :)
from django.views.decorators.http import require_http_mothods
@require_http_methods(["GET", "POST"])
def my_view(request):
pass
There is a "@" in above example. But I could not figure out that. Thanks in advance. :)
@
is used to decorate
a function. This mechanism is called a decorator
.
A decorator is a function that will modify the behavior of another function.
In your case, the require_http_methods
decorator checks that the request is a GET or a POST method before calling the my_view
function.
It's a very powerful mechanism and I do recommend to spend a little time for understanding it. You can start with this tutorial
I hope it helps