DEV Community

Cover image for Crispy Forms In Django.
Yahaya Kehinde
Yahaya Kehinde

Posted on • Updated on

Crispy Forms In Django.

Crispy forms provide a very neat way of using Bootstrap within our Django templates. For the purpose of this article, we are going to be using bootstrap 4.

The first step is to install crispy form:

pip install django-crispy-forms
Enter fullscreen mode Exit fullscreen mode

Next, go to the settings.py and under installed app, add crispy_forms

Then at the bottom of the settings.py, add

CRISPY_TEMPLATE_PACK = 'bootstrap4'

Enter fullscreen mode Exit fullscreen mode

Lastly, in order to use it, we simplyload the crispy form tag at the top of our template,

{% load crispy_forms_tags %}
Enter fullscreen mode Exit fullscreen mode

and wherever you intend to render your form tag, you use the crispy tag as a template tag using the pipe character '|'

{{form | crispy }}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)