django视图装饰器——Allowed HTTP methods

Allowed HTTP methods
  这些装饰器在django.views.decorators.http中,可以用来限制对视图的访问方式。如果不是规定的方式,那么将返回一个django.http.HttpResponseNotAllowed。

from django.views.decorators.http import require_http_methods

@require_http_methods(["GET", "POST"])
def my_view(request):
 # I can assume now that only GET or POST requests make it this far
 # ...
 pass

还有require_GET()、require_POST()方法,分别只限于使用GET或者POST方法访问。

原文地址:https://www.cnblogs.com/chenjianhong/p/4145093.html