Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django:未设置CSRF cookie_Python_Django_Django Csrf - Fatal编程技术网

Python Django:未设置CSRF cookie

Python 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%} 在生成的页面中

我想在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%}
在生成的页面中,我可以看到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):