About Custom Form Attributes using Django Crispy Forms

You can add custom form attributes to the django-crispy-forms helper by accessing its attrs attribute, like so:

1
2
3
4
form_helper = FormHelper()
form_helper.form_method = "POST"
form_helper.attrs["novalidate"] = "novalidate"
form_helper.attrs["data-hello"] = "Hello, World!"

Tips and Tricks Programming Django 4.2 Django 3.2 Django 2.2 django-crispy-forms