zoukankan      html  css  js  c++  java
  • django CBV模式下如何去掉csrf验证

    方式一:
    from django.views.decorators.csrf import csrf_exempt
    from django.utils.decorators import method_decorator
    from django.views import View
    class Goods_views(View):
    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
    return super(Goods_views,self).dispatch(request, *args, **kwargs)
      def post(request):
        pass
    注:上述代码除了类名(Goods_views)可以替换。其他均不可更改。


    方式二:
    from django.views.decorators.csrf import csrf_exempt
    from django.utils.decorators import method_decorator
    from django.views import View
    @method_decorator(csrf_exempt,name='dispatch')
    class Goods_views(View):
      def post(request):
        pass


  • 相关阅读:
    前端之JavaScript内容
    前端之CSS内容
    前端之HTML内容
    表单提交中的input、button、submit的区别
    PostgreSQL
    PostgreSQL
    PostgreSQL
    JIRA中的标记语言的语法参考
    Markdown
    Linux
  • 原文地址:https://www.cnblogs.com/xshan/p/9566970.html
Copyright © 2011-2022 走看看