Crispy Forms Integration

A snippet showing how to integrate crispy forms with Django.


# Install crispy-forms and Bootstrap 5 plugin
pip install django-crispy-forms crispy-bootstrap5
      

# settings.py (relevant)

INSTALLED_APPS += ["crispy_forms", "crispy_bootstrap5"]
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
      

# forms.py

from django import forms

class ContactForm(forms.Form):
    name = forms.CharField()
    email = forms.EmailField()
    message = forms.CharField(widget=forms.Textarea)
      

<!-- templates/contact.html -->

{% load crispy_forms_tags %}
<form method="post" class="bg-white border rounded p-3">
  {% csrf_token %}
  {{ form|crispy }}
  <button type="submit" class="btn btn-primary">Send</button>
</form>
      
Explanation:
  • crispy-bootstrap5 adds Bootstrap styling without manual widget attrs.
  • Category Forms & Validation
  • Total Views 960
  • Last Modified 02 November, 2025
  • Tags #forms #crispy forms #ui #styling
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.