Django shorts: #3 Crispy forms

Arno Pretorius
1 min readOct 16, 2022

How to setup crispy forms in Django.

Photo by AltumCode on Unsplash

What are crispy forms?

Crispy forms is a python package which we can implement within our Django web application. It is used to improve the quality and design of our user forms.

.

.

.

Step 1:

First of you head over to your terminal and install django-crispy-forms via the following command:

pip install django-crispy-forms

Step 2:

Next you will need to add the django-crispy-forms to our installed apps in settings.py as follows:

INSTALLED_APPS = [...'crispy_forms',
]

Step 3:

You also need to be sure that you add the bootstrap crispy template pack under your installed apps:

INSTALLED_APPS = [...'crispy_forms',
]CRISPY_TEMPLATE_PACK='bootstrap4'

Step 4:

Create a basic html page, as follows:

<!--index.html--><form method="post">    {% csrf_token %}    {{form}}    <button type="submit" class="btn btn-primary"> Log in </button></form>

Step 5:

Add the following tag of crispy forms at the top of your html page:

<!--index.html-->{% load crispy_forms_tags %}

Step 6:

Add the crispy forms filter to your form:

|crispy

<!--index.html--><form method="post">    {% csrf_token %}    {{form|crispy}}    <button type="submit" class="btn btn-primary"> Log in </button></form>

->

Originally published at https://www.cloudwithdjango.com on October 16, 2022.

--

--

Arno Pretorius

Hi, I’m Arno… I love cloud computing and django web development and I want to share my knowledge and experiences with you.