Reputation: 1567
I am trying to customize the PasswordResetForm form of django.contrib.auth.views.password_reset
. I copied the code from Django's website or the one GitHub, and put it in my forms.py. I changed the code from:
email = forms.EmailField(label=_("Email"), max_length=254)
to
email = forms.EmailField(label=_("Email"), max_length=254, widget=forms.EmailInput(attrs={'placeholder': 'E-mail'}))
and kept the remaining PasswordResetForm
code intact.
url(r'^password/reset/$','django.contrib.auth.views.password_reset', {'post_reset_redirect': '/password/reset/done/', 'password_reset_form': 'forms.PasswordResetForm',}, name="password_reset"),
However I am getting the following error:
Exception Location: /Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/contrib/auth/views.py in password_reset, line 185
185. form = password_reset_form()
I had it working without this customisation. I need the customisation because I want a PlaceHolder
in the field. If I remove the key in the url it works.
Upvotes: 1
Views: 221
Reputation: 308939
The value for password_reset_form
should be the actual form class, not a string path to the form. For example, if you import the form with
from forms import PasswordResetForm
Then you would do:
url(r'^password/reset/$', 'django.contrib.auth.views.password_reset', {'post_reset_redirect': '/password/reset/done/', 'password_reset_form': PasswordResetForm}, name="password_reset"),
As an aside, using the string view like django.contrib.auth.views.password_reset
is deprecated in Django 1.8, and will stop working in Django 1.10. Instead, you can import the auth views,
from django.contrib.auth import views as auth_views
and change the url pattern to
url(r'^password/reset/$', auth_views.password_reset, {'post_reset_redirect': '/password/reset/done/', 'password_reset_form': PasswordResetForm}, name="password_reset"),
Upvotes: 6