Python Django:未设置CSRF cookie
我想在django项目中发布一个表单,导致“CSRF cookie not set.”错误 views.py index.htmlPython Django:未设置CSRF cookie,python,django,django-csrf,Python,Django,Django Csrf,我想在django项目中发布一个表单,导致“CSRF cookie not set.”错误 views.py index.html {%extends'base.html%} {%block title%}BikeMiles{%endblock%} {%block content%} 格法雷内公里 资料 评释书 阿基翁 {eIntrage%中eintrag的%s} {{eintrag.kommentar}} {%csrf_令牌%} {%endfor%} {%endblock%} 在生成的页面中
{%extends'base.html%}
{%block title%}BikeMiles{%endblock%}
{%block content%}
格法雷内公里
资料
评释书
阿基翁
{eIntrage%中eintrag的%s}
{{eintrag.kommentar}}
{%csrf_令牌%}
{%endfor%}
{%endblock%}
在生成的页面中,我可以看到csrf输入字段:
<input type='hidden' name='csrfmiddlewaretoken' value='zzRnENjz6wrUP8Op8IVOIDsUVvclY37k' />
你知道怎么解决吗 我刚才遇到了这个问题: 简而言之,将
@确保\u csrf\u cookie
放在视图定义之前
i、 e
如果更改
action=”会发生什么情况http://127.0.0.1:8000/“
至action=“/”>
?ah可能重复使用修复路径重新绘制URL。奇怪。多谢各位
{% extends 'base.html' %}
{% block title %}BikeMiles{% endblock %}
{% block content %}
<div class="col-md-12">
<table class="table table-striped">
<tr>
<th>gefahrene KM</th>
<th>Datum</th>
<th>Kommentar</th>
<th>Aktion</th>
{% for eintrag in Eintraege %}
<tr>
<td>{{ eintrag.kommentar }}</td>
<form method="post" action="http://127.0.0.1:8000/">
{% csrf_token %}
<input type="hidden" name="id" value="{{eintrag.id}}">
<input type="submit" class="btn btn-xs btn-danger" value="delete" >
</form>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
<input type='hidden' name='csrfmiddlewaretoken' value='zzRnENjz6wrUP8Op8IVOIDsUVvclY37k' />
# Create your views here.
@ensure_csrf_cookie
def index(request):