post提交表单报错:

Forbidden (403)

CSRF verification failed. Request aborted.

You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties.

If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for 'same-origin' requests.

Help

Reason given for failure:

    CSRF cookie not set.
    

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.

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.

解决方法如下红色代码:

# coding:utf-8
from django.shortcuts import render_to_response
from blog.models import Blog
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt def index(request):
blog_list=Blog.objects.all() #Blog.objects.all()获取Blog表中所有数据,并赋值给blog_list
return render_to_response('index.html',{'blogs':blog_list}) #返回给浏览器一个index.html页面,并且将blog_list变量的值也返回给index.html @csrf_exempt
def login(request):
username=request.POST.get('username','')
password=request.POST.get('password','')
if username == 'chen' and password == '123456':
return HttpResponse('login success!')
else:
return render_to_response('index.html',{'error':'username or password error!'})

最新文章

  1. c 进程间的通信
  2. 【SQL】找出行数与自增标识值不相等的表(即有缺行)
  3. 绘制图形与3D增强技巧(三)----三角形图元TRANGLE
  4. Android 简易XML解析
  5. ✡ leetcode 159. Longest Substring with At Most Two Distinct Characters 求两个字母组成的最大子串长度 --------- java
  6. IOS 项目 小说 1
  7. Oracle的rownum原理和使用(整理几个达人的帖子)
  8. Android Viewpager PagerAdapter update data 刷新界面数据
  9. 我、实战nginx+naxsi(WAF)之一
  10. Delphi实用小function
  11. hdu 2642 Stars
  12. 数据结构-B树
  13. 无线网破解软件|一键式破解无线网|BT17软件包下载[笔记本+软件就行]
  14. Cloud Foundry 中国群英会【上海站、成都站】资料宣传
  15. 关于Relay Log无法自己主动删除的问题(Neither --relay-log nor --relay-log-index were used)
  16. Unity3d 物体沿着正七边形轨迹移动
  17. easyUI创建人员树
  18. 【微服务】之二:从零开始,轻松搞定SpringCloud微服务系列--注册中心(一)
  19. 读《Linux Shell脚本攻略》(第2版) 总结
  20. java.lang.IllegalArgumentException异常 返回值类型的问题

热门文章

  1. 第二百一十四节,jQuery EasyUI,Calendar(日历)组件
  2. 2-XOR-SAT (种类并查集)
  3. debug命令
  4. Android--推断文本文件编码
  5. 一站式WPF--依赖属性(DependencyProperty)二
  6. asp.net正则表达式删除指定的HTML标签的代码
  7. uva 10494 - If We Were a Child Again 大数除法和取余
  8. JavaScript------字符串中各种方法
  9. 两天学会DirectX 3D之第二天
  10. "_dns_free_resource_record", referenced from:问题