Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

easy way to get crispy forms to work with django-filter

specifically, using the example template in the django-filter docs:

{% extends "base.html" %}

{% block content %}
<form action="" method="get">
    {{ filter.form.as_p }}
    <input type="submit" />
</form>
{% for obj in filter %}
    {{ obj.name }} - ${{ obj.price }}<br />
{% endfor %}
{% endblock %}

Do others know how to get crispy forms to work?

Inserting the following makes the form render nicely, but I can't get it to actually be functional.

{% crispy filter.form %}

figured it out - was too easy. I swear I tried this method several times earlier, although I must have been doing something wrong. Sorry to ask such a simple question.

Answer is to change:

{{ filter.form.as_p }}

To:

{{ filter.form|crispy }}
like image 442
user3356491 Avatar asked Feb 26 '14 15:02

user3356491


People also ask

Why use Django crispy forms?

Django-crispy-forms is an application that helps to manage Django forms. It allows adjusting forms' properties (such as method, send button or CSS classes) on the backend without having to re-write them in the template.

What is crispy form tags in Django?

django-crispy-forms provides you with a |crispy filter and {% crispy %} tag that will let you control the rendering behavior of your Django forms in a very elegant and DRY way. Have full control without writing custom form templates.


1 Answers

I just needed to add the load crispy tags.

{% extends "base.html" %}
{% load crispy_forms_tags %}

{% block content %}
    <form action="" method="get">
        {{ filter.form|crispy }}
        <input type="submit" />
    </form>
    {% for obj in filter %}
        {{ obj.name }} - ${{ obj.price }}<br />
    {% endfor %}
{% endblock %}
like image 174
hum3 Avatar answered Oct 06 '22 01:10

hum3