首页 > 其他 > 详细

django中CBV加csrf_exempt函数问题

时间:2019-10-29 21:53:29      阅读:90      评论:0      收藏:0      [点我收藏+]

CSRF Token相关装饰器在CBV只能加到dispatch方法上

备注:

1. csrf_protect,为当前函数强制设置防跨站请求伪造功能,即便settings中没有设置全局中间件。
2. csrf_exempt,取消当前函数防跨站请求伪造功能,即便settings中设置了全局中间件
from django.views.decorators.csrf import csrf_exempt, csrf_protect
 
class HomeView(View):
 
    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        return super(HomeView, self).dispatch(request, *args, **kwargs)
 
    def get(self, request):
        return render(request, "home.html")
 
    def post(self, request):
        print("Home View POST method...")
        return redirect("/index/")

 

django中CBV加csrf_exempt函数问题

原文:https://www.cnblogs.com/taosiyu/p/11761335.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!