Python web-Django CSRF跨站请求伪造防护( 六 )

from django.views.decorators.csrf import csrf_exemptcsrf_protect

@csrf_exempt

def login(request):

if request.method == 'GET':

return render(request'login.html')

else:

return HttpResponse('ok')

2、如果是类视图 , 需要使用方法装饰器进行封装

from django.utils.decorators import method_decorator

from django.views.decorators.csrf import csrf_exemptcsrf_protect

from django.views.generic import TemplateView

@method_decorator(csrf_exempt)

class LoginView(TemplateView):

template_name = 'login.html'

推荐阅读