Django Crispy Forms

Django crispy forms help in rending a prettier-looking form element without working on the HTML or CSS elements. If you use the ModelForm concept in Django, Crispy forms are the easiest way to render a clean form element.

This tutorial explains all aspects of using a Django Crispy Form in your web application step-by-step.

Step 1: Install Django Crispy Forms

pip install django-crispy-forms

Add crispy_forms in your settings.py file under the list of INSTALLED_APPS

INSTALLED_APPS = [
  ...
  'crispy_forms',
]

Step 2: Select Template Pack for Django Crispy Forms

Django Crispy Forms have built-in support for CSS frameworks like bootstrap, bootstrap3, bootstrap4, foundation, uni-form, and tailwind. To select a template pack add the below code in settings.py :

CRISPY_TEMPLATE_PACK = 'uni_form'

You may use other CSS frameworks like bootstrap or foundation.

Step 3: Apply crispy tag to your form element

In order to apply the crispy tag to your ModelForm object use the code below

{% load crispy_forms_tags % }

<form method="post" class="uniForm">
    {{ form|crispy } }
</form>

You may use other CSS classes like bootstrap or foundation.

That's it. You are set. Your form element will now look crispy.