本文主要是介绍CSRF verification failed. Request aborted,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在django中利用comments功能,发生错误,错误信息如下:CSRF verification failed. Request aborted.
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 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.
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.
点击(此处)折叠或打开
- def archive(request,text_id):
- all_posts = TextBody.objects.all()
- posts = all_posts.filter(id=text_id)
- t= loader.get_template('content.html')
- c = Context({'posts':posts})
- return HttpResponse( t.render(c) )
点击(此处)折叠或打开
- <table>
- <form action="{% comment_form_target %}" method="post">
- {% csrf_token %}
- {{ form }}
- <tr>
- <td colspan="2">
- <input type="submit" name="submit" value="Post">
- <input type="submit" name="preview" value="Preview">
- </td>
- </tr>
- </form>
- </table>
- python 自动化测试平台 Robot ...
- python snmp 自动化2-在python...
- python snmp 自动化测试1-安装...
- 自动化测试详细测试计划 模板...
- python snmp 自动化3-修改pyth...
- Python 动态创建类
- 一个基于multiprocessing的并...
- Python 数据库管理与操作...
- 利用Bicho抓取基于Jira的缺陷...
- Lua中的协程即协同程序...
这篇关于CSRF verification failed. Request aborted的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!