0
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. :)

user2864740
  • 57,407
  • 13
  • 129
  • 202
nextdoordoc
  • 1,605
  • 5
  • 20
  • 29

1 Answers1

1

@ 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

luc
  • 39,890
  • 22
  • 125
  • 171