Search code examples
pythonhtmldjangopython-3.x

Invalid block tag on line 8: 'crsf_token', expected 'endblock'. Did you forget to register or load this tag?


I have a problem, can't see the difference between two codes. First isn't working and second works. I'm getting this: "Invalid block tag on line 8: 'crsf_token', expected 'endblock' . Did you forget to register or load this tag?" Thanks for answers.

First:

{% extends 'basic_app/base.html' %}
{% block body_block %}
    <div class="container">
        <div class="jumbotron">
            <h1>Please Login</h1>

                <form method="post" action="{% url 'basic_app:user_login' %}">
                    {% crsf_token %}
                    <label for="username">Username:</label>
                    <input type="text" name="username" placeholder="Enter Username">

                    <label for="password">Password:</label>
                    <input type="password" name="password">

                    <input type="submit" name="" value="Login">

                </form>
        </div>
    </div>
{% endblock %}

Second:

{% extends 'basic_app/base.html' %}
{% block body_block %}
  <div class="container">
    <div class="jumbotron">
      <h1>Please Login</h1>

        <form method="post" action="{% url 'basic_app:user_login' %}">
          {% csrf_token %}
          {# A more "HTML" way of creating the login form#}
          <label for="username">Username:</label>
          <input type="text" name="username" placeholder="Username">

          <label for="password"></label>
          <input type="password" name="password">

          <input type="submit" name="" value="Login">

        </form>

    </div>
  </div>
{% endblock %}

Solution

  • You misspelled the tag name in the first example.

    It's csrf_token, not crsf_token.