C:\Users\x\pyp1>python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
June 07, 2018 - 22:06:45
Django version 2.0.6, using settings 'pyp1.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[07/Jun/2018 22:06:51] "GET /polls/login/ HTTP/1.1" 200 2403
[07/Jun/2018 22:06:51] "GET /static/bootstrap/css/bootstrap.min.css HTTP/1.1" 404 1717
[07/Jun/2018 22:06:51] "GET /static/fontawesome/css/font-awesome.min.css HTTP/1.1" 404 1732
Forbidden (CSRF token missing or incorrect.): /polls/login/
[07/Jun/2018 22:06:53] "POST /polls/login/ HTTP/1.1" 403 2513

Forbidden (403)

CSRF verification failed. Request aborted.

Help

Reason given for failure:

    CSRF token missing or incorrect.
    

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 passes a request to the template's render method.
  • 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.
  • The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login.

You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.

You can customize this page using the CSRF_FAILURE_VIEW setting.


注释掉settings.py中csrf 那一行

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

资源文件404问题解决
在settings.py中加入
# 静态文件夹的位置
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]

django 403问题的更多相关文章

  1. Django 403错误:CSRF verification failed. Request aborted

    网上有解决办法,我自己的组合是: 一,FORM加标识 <form action="" method="post"> {% csrf_token %} ...

  2. Django1.8:403错误:CSRF verification failed. Request aborted.

    问题:Django 403错误:CSRF verification failed. Request aborted.     原因:需要加cookie验证 解决方法: 1.在view.py中增加 fr ...

  3. Apache2.4部署django出现403 Forbidden错误解决办法

    前言:Apache2.4部署django出现403 Forbidden错误最好要结合apache中的错误日志来观察出现何种错误导致出现403错误 下午百度了一下午没找到解决办法,试了n种方法,简直坑爹 ...

  4. django http 403 错误

    在使用android的xUtils框架提交post请求到django服务器上面,出现错误,返回Forbiddeen.解决方法记录于此. 参考链接 http://blog.csdn.net/liangp ...

  5. django post报403问题

    第一个问题是: 我使用jquery的ajax向后台传值, 当使用GET方法时没问题 $.ajax({ type:"GET" url: data: success: }) 但是由于基 ...

  6. Django提交表单时遇到403错误:CSRF verification failed

    这个问题是由跨站点伪造请求(CRSF)造成的,要彻底的弄懂这个问题就要理解什么是CRSF,以及Django提供的CSRF防护机制是怎么工作的. 什么是CSRF CSRF, Cross Site Req ...

  7. Django的POST请求时因为开启防止csrf,报403错误,及四种解决方法

    Django默认开启防止csrf(跨站点请求伪造)攻击,在post请求时,没有上传 csrf字段,导致校验失败,报403错误 解决方法1: 注释掉此段代码,即可. 缺点:导致Django项目完全无法防 ...

  8. 解决Django + DRF:403 FORBIDDEN:CSRF令牌丢失或不正确,{"detail":"CSRF Failed: CSRF cookie not set."}

    我有一个Android客户端应用程序尝试使用Django + DRF后端进行身份验证.但是,当我尝试登录时,我收到以下响应: 403: CSRF Failed: CSRF token missing ...

  9. django csrf使用教程,解决Forbidden (403)CSRF verification failed. Request aborted.

    Django版本号:1.11.15 django中post请求报错:Forbidden (403)CSRF verification failed. Request aborted. HelpReas ...

随机推荐

  1. mooc linux学习总结

    通过八周的学习获得了很多知识.       首先,通过网课老师形象生动的讲述和描述一些专业词汇,使我更加深刻的记住并掌握了这些内容:动态的展示堆栈的变化,更容易理解一段汇编代码:分析操作系统的工作,记 ...

  2. Linux内核分析第二周:操作系统是如何工作的

    第一讲 函数调用堆栈 计算机是如何工作的? (总结)——三个法宝 1,存储程序计算机工作模型,计算机系统最最基础性的逻辑结构: 2,函数调用堆栈,高级语言得以运行的基础,只有机器语言和汇编语言的时候堆 ...

  3. 《Linux内核分析》期终总结

    作者:杨舒雯,原创作品转载请注明出处,<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 目录: 1.通过简 ...

  4. 第二个spring

    由于第一个spring已经完成,我们现在进去第二个spring! 陈志棚:成绩的统筹 李天麟:界面音乐 徐侃:代码算法   plan好布局,分配任务,控制时间!

  5. 实验1--用C语言编程四则运算

    #include<stdio.h>#include<stdlib.h>#include <time.h>#define N 30main(){int a,b,k,i ...

  6. Spring整合SpringMVC

    整合:把在springMVC配置文件中的spring提取出来整合为另一份配置文件 希望: 1).Spring的配置文件只是用来配置和业务逻辑有关的功能(数据源.事务控制.切面....) 2).Spri ...

  7. Java控制台常用命令

    http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html javaw是java的带console版本,其他一致. h ...

  8. TestNG—学习笔记2

    关于TestNG,也是一边学一边总结,对于TestNG和Junit的比较其实也没有什么意义,都是一种测试框架,都是为了应用而生的东西,没有必要说谁好谁不好了.用的熟练用的好就是真的好啊. 下面简单的总 ...

  9. 批处理-For详解

    大纲 一 前言 二 for语句的基本用法 三 for /f (delims.tokens.skip.eol.userbackq.变量延迟) 四 for /r (递归遍历) 五 for /d (遍历目录 ...

  10. python之tkinter使用-滚动条

    # GUI:tkinter使用 # 通过调节滚动条改变标签中字体大小 import tkinter as tk def resize(ev=None): '''改变label字体大小''' label ...