练习Django表单提交时遇到如下问题:

在网上各种查找,终于找到了解决方法。

1.在from 表单中添加 {% csrf_token %}

2.在视图中添加 from django.template import RequestContext 导入项,并且在return 返回中添加context_instance=RequestContext(request)

<form  role="form" method="post" action="login">
{% csrf_token %}
<input name="userName" type="text" class="text" placeholder="账号" required="" >
<input name="password" type="password" placeholder="密码" required >
<div class="submit"><input type="submit" value="登录"></div>
</form>
from django.template import  RequestContext

def index(request):
return render_to_response("login.html",context_instance=RequestContext(request)) def login(request):
return render_to_response("index.html")

再测试就OK了。

django之所以引进CSRF是为了避免Cross Site Request Forgeries攻击

django错误 - Reason given for failure: CSRF cookie not set.的更多相关文章

  1. (转载)django 访问url报错Forbidden (CSRF cookie not set.): xxx 问

    原地址:http://www.cnblogs.com/meitian/p/7016336.html 问题:页面访问时报错 Forbidden (CSRF cookie not set.): xxx   ...

  2. 练习django 访问url报错Forbidden (CSRF cookie not set.)

    解决方法是把setting中csrf那行注释掉: MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.con ...

  3. Django CSRF cookie not set.错误

    post提交表单报错: Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message b ...

  4. Django(六)Session、CSRF、中间件

    大纲 二.session 1.session与cookie对比 2.session基本原理及流程 3.session服务器操作(获取值.设置值.清空值) 4.session通用配置(在配置文件中) 5 ...

  5. (django1.10)访问url报错Forbidden (CSRF cookie not set.): xxx

    问题:页面访问时报错 Forbidden (CSRF cookie not set.): xxx     解决方法: 修改settings.py文件,注释掉 django.middleware.csr ...

  6. Django框架 之 基于Ajax中csrf跨站请求伪造

    Django框架 之 基于Ajax中csrf跨站请求伪造 ajax中csrf跨站请求伪造 方式一 1 2 3 $.ajaxSetup({     data: {csrfmiddlewaretoken: ...

  7. django中给ajax提交加上csrf

    代码来自djangoproject网站 在html中的script标签下插入下面代码 在html文档加载时候运行下面代码,并且使用$.ajaxSetup设置ajax每次调用时候传入的数据,$.ajax ...

  8. 第四百零五节,centos7下搭建sentry错误日志服务器,接收python以及Django错误,

    第四百零五节,centos7下搭建sentry错误日志服务器,接收python以及Django错误, 注意:版本,不然会报错 Docker >=1.11Compose >1.6.0 通过d ...

  9. DJango错误日志生成

    DJango错误日志生成 setting.py设置 LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': ...

随机推荐

  1. 标准C程序设计七---21

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  2. Set 技巧之一

    我们知道set中 用set<int,int>S; S.lower_bound(x): 查找Set中 第一个>=x的数,返回结果是指针. S.upper_bound(x):查找Set中 ...

  3. Atcoder 2373 Cookie Exchanges

    Problem Statement Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively ...

  4. How to Upgrade PIP in Windows

    https://datatofish.com/upgrade-pip/ 这个网站写的非常的全

  5. Centos常用命名

    1.关机 (系统的关机.重启以及登出 ) 的命令 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours: ...

  6. Windows下使用Nexus搭建Maven私服(安装)

    一.下载Nexus 下载OSS最新版:https://www.sonatype.com/download-oss-sonatype 老版本:https://support.sonatype.com/h ...

  7. 高级算法设计讲义 Lecture Notes for Advanced Algorithm Design

    (Last modification: 2012-12-17) Textbooks: (1) David Williamson, David Shmoys. The Design of Approxi ...

  8. Android开发系列(二十一):Spinner的功能和使用方法以及实现列表选择框

    Spinner是一个列表选择框.相当于弹出一个菜单供用户进行选择. Spinner继承AdapterView Spinnet支持的XML的属性: android:entries:使用数组资源设置该下拉 ...

  9. 如何在List集合中去重

    众所周知List集合中的元素是有序的,但是List中的元素同样是可以重复的,那么我们应该怎么在List集合中去重呢? 方法一: 对于方法一而言,这也许是一个小窍门.利用的是Set集合中不允许出现重复的 ...

  10. Maven实现Web应用集成測试自己主动化 -- 測试自己主动化(WebTest Maven Plugin)

    近期在appfuse看到使用webtest-maven-plugin实现Web应用的集成測试,研究了下.感觉很不错.对于Web应用自己主动构建很有帮助,在性能測试之前能够保证Web应用的基本功能工作正 ...