zoukankan      html  css  js  c++  java
  • Forbidden (403) CSRF verification failed. Request aborted.

      学习django1.4,没有中文资料,只能慢慢啃官方教程。

      最近被这个问题纠结几天了,一直没有解决,虽然用的是业余时间,但是这个问题不解决,后面的教程感觉都做不下去了。这个问题是这样长生的:我用post方法提交表单,出现标题那个错误,django错误系统也给出了三个途径,除了第三个没有完全懂之外,其它的都试了好多遍了。最后却发现在setting里面把CSRF的注释掉就正确了。还是把django的提示贴出来吧(不过没有用哦):

      

    In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:
    Your browser is accepting cookies.
    The view function uses RequestContext for the template, instead of Context.
    In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
    If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.

      最后成功的解决办法:在setting.py修改如下。

    MIDDLEWARE_CLASSES = (
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        #'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        
        # Uncomment the next line for simple clickjacking protection:
        # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
    )

      这是我自学python的第一个帖子吧,也算是开了第一篇了,虽然简单,自己感觉还是蛮艰难的。

  • 相关阅读:
    第三方模块加载时出现XXX运行 提示错误:无法加载文件 C:UsersgxfAppDataRoaming pmXXX.ps1,因为在此系统上禁止运行脚本。
    node模块化
    前端面试集锦
    将字符转换成驼峰表示法
    JavaScript数据处理
    大数据基础整合
    移动端网页特效
    本地存储
    DOM重点核心
    触发器SQL
  • 原文地址:https://www.cnblogs.com/slider/p/2549955.html
Copyright © 2011-2022 走看看