django request limit

django.views.decorators.http Decorator bag can restrict access to a view request-based methods.

Restrictions can only view service http method specified. usage:

from django.views.decorators.http import require_http_methods, require_GET, require_POST
# @require_http_methods(['GET','POST'])#必须大写
@require_GET
# @require_POST
def tags(request):
    print("hello")
    return render(request,'mytags.html')
Note that the method name must be capitalized.

require_GET()

View only accepts decorator GET method.

require_POST()

View only accepts decorator POST method.

require_safe()

View only accepts and decorators GET HEAD method. These methods are generally considered to be safe, because the method should not have a purpose other than the requested resource.

Note

Django will automatically clear the contents of the response of HEAD request and retain only the head, so in your view, the way you handle HEAD requests may be totally consistent with the GET request. Because some software, such as a link checker, depending on the HEAD request, so you probably should use require_safeinstead require_GET.

Guess you like

Origin www.cnblogs.com/pfeiliu/p/11924788.html