How to Install and use Django Crispy Forms

Crispy forms is a third party django app that makes styling forms really simple. It makes your forms look beautiful with almost no effort from your side. It supports different template packs like uni-form, foundation, bootstrap and bootstrap3 , that’s what we will be using.

Setting it up is simple as well with these few steps that I have shown below

1. Install django-crispy-form package with pip (make sure you have pip installed)

pip install --upgrade django-crispy-forms

2. add it to Installed apps in your project’s settings.py file

INSTALLED_APPS = (
...
'crispy_forms',
)



3. add this line in your settings.py file

CRISPY_TEMPLATE_PACK = 'bootstrap3'

Now, crispy forms is ready to be used.. let’s see how.


4. Put these tags at the top of your html template file (but below extends tags, if any) where you want to use crispy forms.

{% load crispy_forms_tags %}



5. Finally, use with {{ form|crispy }} make your form look crispy!

<form method="post">
{% csrf_token %}
{{ form|crispy }}
<input class="btn btn-default" type="submit" value="Submit" />
>/form>

Leave a Reply

Your email address will not be published.