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 }}
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.
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.
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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With