[Solved]-Receiving 'invalid form: crispy' error when trying to use crispy forms filter on a form in Django, but only in one django app and not the other?

10πŸ‘

βœ…

I had the same problem but was resolved after loading crispy {% load crispy_forms_tags %} form at the top of my templates

    {% extends 'base.html' %} {% block content %}
    {% load crispy_forms_tags %}

<div class="container">
  <div class="row">
    <div class="col-md-8 card mb-4  mt-3 left  top">
      <div class="card-body">
        <h1>{% block title %} {{ post.title }} {% endblock title %}</h1>
        <p class=" text-muted">{{ post.author }} | {{ post.created_on }}</p>
        <p class="card-text ">{{ post.content | safe }}</p>
      </div>
    </div>
    {% block sidebar %} {% include 'sidebar.html' %} {% endblock sidebar %}

    <div class="col-md-8 card mb-4  mt-3 ">
      <div class="card-body">
        <!-- comments -->
        <h2>{{ comments.count }} comments</h2>

        {% for comment in comments %}
        <div class="comments" style="padding: 10px;">
          <p class="font-weight-bold">
            {{ comment.name }}
            <span class=" text-muted font-weight-normal">
              {{ comment.created_on }}
            </span>
          </p>
          {{ comment.body | linebreaks }}
        </div>
        {% endfor %}
      </div>
    </div>
    <div class="col-md-8 card mb-4  mt-3 ">
      <div class="card-body">
        {% if new_comment %}
        <div class="alert alert-success" role="alert">
          Your comment is awaiting moderation
        </div>
        {% else %}
        <h3>Leave a comment</h3>
    
        <form method="post" style="margin-top: 1.3em;">
          {{ comment_form | crispy }}
          {% csrf_token %}
          <button type="submit" class="btn btn-primary  btn-lg">Submit</button>
        </form>

        {% endif %}
      </div>
    </div>
  </div>
</div>
{% endblock content %}
πŸ‘€Darkhorse

4πŸ‘

please make shour that you include the {% load crispy_forms_tags %} inside the partials like :

{% extends 'posts/bases/base.html' %}
{% load crispy_forms_tags %}
{% block title%}
<title>Register</title>
{% endblock %}

{% block content%}
<h1>Register</h1>
<form action="" method="post">
{% csrf_token %}

{{ form|crispy }}
<button type="submit">Register</button>
</form>

{% endblock %}

if you load it in the base.html will not work

Django==3.1.4

django-crispy-forms==1.10.0

2πŸ‘

I have the same error…You’are using (), like that:
(% load crispy_forms_tags %)
and not {}, like:
{% load crispy_forms_tags %}

0πŸ‘

A basic error (I often make) is that even though you load crispy_form_tags, you actually use crispy. The error Invalid filter: 'crispy_forms_tags' may show up if you use {{form|crispy_forms_tags}} instead of {{form|crispy}}.

{% load crispy_forms_tags %}

{{ login_form | crispy_forms_tags }}   /* <--- Invalid filter: 'crispy_forms_tags' */

{{ login_form | crispy }}              /* <--- OK */
πŸ‘€cottontail

Leave a comment