I’m using django-registration. I’d like to update the AuthenticationForm in ‘django.contrib.auth.forms’. Specifically, I would like to pass the ‘attrs’ dict to add a few attributes. How do I update a form that comes with django?
I’m using django-registration. I’d like to update the AuthenticationForm in ‘django.contrib.auth.forms’. Specifically, I would
Share
The standard way is to subclass AuthenticationForm, change the attrs in constructor, pass the form to login view and write a new entry in urls.py.
This is a nightmare: in order to add html attribute to a field it is necessary to use python subclassing, to know how exactly django’s form metaclass work (
self.fields['field'].widget.attrs, not justself.field.widget.attrs), to know regexes (for urls.py), to know how django’s urls.py work (should you put the overriding line before of afterinclude('django.contrib.auth.urls')?) and to know where is the auth form and auth view imported from.And now the “commercial break”: just use http://pypi.python.org/pypi/django-widget-tweaks for your task 😉