I am new in crispy form configuration. I have a django form and want to setup autocomplete = off thoughout the form. I found this attribute can be set within field widget. But instead of individual input , how can we apply whole form in a single line?
You can specify this at the <form>
tag, for example:
<form autocomplete="off" method="post" action="some-url">
{% crisply my_form %}
</form>
or if you work with a FormHelper
, you can specify the attrs
:
from crispy_forms.helper import FormHelper
class ExampleForm(forms.Form):
def __init__(self, *args, **kwargs):
super(ExampleForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.attrs['autocomplete'] = 'off'
That being said, turning autocomplete
off is sometimes a security hazard, since it sometimes forces users to use simple passwords, over more complicated ones. Therefore some browsers start to ignore this attribute.