Django rest-framework authentication frame -CSRF

There is a middleware settings.py

django.middleware.csrf.CsrfViewmiddleware # If you do not need to comment out the station's open csrf verify if the entire station to be used globally csrf certification verification csrf

csrf-token is implemented django middleware

 

from django.views.decorators.csrf import csrf_exempt,csrf_protect
from django.utils.decorators import method_decorator

# Decorator added to the function

@csrf_protect # decorator This function requires csrf token authentication
@csrf_exempt # decorator exempt csrf token authentication
DEF update_order (Request):
      return String

 

# Class to which the method of adding decorators

1. The first way

the Test class (View):
  @method_decorator (csrf_exempt) # class to which the method of adding a decoration method requires introducing method_decorator
  DEF GET (Self, Request):
    return the HttpResponse ( "Test")

2. The second way

@method_decorator (csrf_exempt, name = 'get ') # found inside the class get method plus decorators csrf_exempt
class the Test (View):
    DEF get (Self, Request):
     return the HttpResponse ( "Test")

Guess you like

Origin www.cnblogs.com/kuku0223/p/11327023.html