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
  • 60,010
  • 15
  • 145
  • 220
nextdoordoc
  • 1,727
  • 6
  • 20
  • 30

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
  • 41,928
  • 25
  • 127
  • 172