Python Django HTML csrf令牌无效

时间:2017-07-21 17:20:42

标签: python html django

我正在尝试在我的帖子表格中输入一个csrf令牌,但我一直收到一个我无法调试的错误

{% extends 'base.html' %}


{% block title %}Data Services{% endblock %}
{% block content %}
<h1>{{ deal_name }}</h1>
<a href="http://127.0.0.1:8000/pick/">Return to Deals here</a>
<p>Which lender do you need to send an email to? </p>
{% if unpaid %}
<form action="/pick/{{ type_id }}/lenders/" method="post">{% csrf token %}
    <select name="email_name">
            {% for l in unpaid %}
            <option value="{{ l.name }}">{{ l.name }}</option>
            {% endfor %}
        </select>
        <input type="submit" value="Email">
    </form>
    {% endif %}
<div>
    <ul>
    {% if lender %}
        There are {{ lender|length }} lenders who have paid.
        {% for l in lender %}
            <li> {{ l.name }} </li>
        {% endfor %}
    {% else %}
        <li> As of now no Lenders have been recorded as paid. </li>
    {% endif %}
    </ul>
</div>
{% endblock %}

我的错误:

第10行的无效块标记:'csrf',预期'elif','else'或'endif'。您是否忘记注册或加载此标记?

就像我在这里错过了一些东西?我已多次尝试过这样的尝试。

2 个答案:

答案 0 :(得分:1)

您没有正确使用该标签。两个词之间没有空格:

{% csrf_token %}

您可以通过CSRF教程(再次)确保所有其他必要部分到位:

Cross Site Request Forgery protection

答案 1 :(得分:1)

标记为{% csrf_token %},而不是{% csrf token %}