0
votes

I have the Django allauth package included into my project. I am trying to create a custom view of the reset password page with also a custom form. Here's what I have:

urls.py

urlpatterns = [
    url(r'^password/reset/$', views.ResetPasswordView.as_view(), name='password-reset'),
]

views.py

class ResetPasswordView(PasswordResetView):
    template_name = 'account/password-reset.html'
    form_class = ResetPasswordForm

forms.py

class ResetPasswordForm(PasswordResetForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['email'].label = ""
        self.fields['email'].widget = forms.EmailInput(attrs={"placeholder": "Email Address"})

However, for some reason when I enter an email address to reset a password, I get the following error:

Traceback:

File "C:\python3.6.3\lib\site-packages\django\core\handlers\exception.py" in inner 41. response = get_response(request)

File "C:\python3.6.3\lib\site-packages\django\core\handlers\base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request)

File "C:\python3.6.3\lib\site-packages\django\core\handlers\base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\python3.6.3\lib\site-packages\django\views\generic\base.py" in view 68. return self.dispatch(request, *args, **kwargs)

File "C:\python3.6.3\lib\site-packages\django\views\generic\base.py" in dispatch 88. return handler(request, *args, **kwargs)

File "C:\python3.6.3\lib\site-packages\allauth\account\views.py" in post 102. response = self.form_valid(form)

File "C:\python3.6.3\lib\site-packages\allauth\account\views.py" in form_valid 639. form.save(self.request)

File "C:\python3.6.3\lib\site-packages\django\contrib\auth\forms.py" in save 269. for user in self.get_users(email):

File "C:\python3.6.3\lib\site-packages\django\contrib\auth\forms.py" in get_users 254. 'is_active': True,

File "C:\python3.6.3\lib\site-packages\django\db\models\manager.py" in manager_method 85. return getattr(self.get_queryset(), name)(*args, **kwargs)

File "C:\python3.6.3\lib\site-packages\django\db\models\query.py" in filter 784. return self._filter_or_exclude(False, *args, **kwargs)

File "C:\python3.6.3\lib\site-packages\django\db\models\query.py" in _filter_or_exclude 802. clone.query.add_q(Q(*args, **kwargs))

File "C:\python3.6.3\lib\site-packages\django\db\models\sql\query.py" in add_q 1250. clause, _ = self._add_q(q_object, self.used_aliases)

File "C:\python3.6.3\lib\site-packages\django\db\models\sql\query.py" in _add_q 1276. allow_joins=allow_joins, split_subq=split_subq,

File "C:\python3.6.3\lib\site-packages\django\db\models\sql\query.py" in build_filter 1154. lookups, parts, reffed_expression = self.solve_lookup_type(arg)

File "C:\python3.6.3\lib\site-packages\django\db\models\sql\query.py" in solve_lookup_type 1034. _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())

File "C:\python3.6.3\lib\site-packages\django\db\models\sql\query.py" in names_to_path 1352. "Choices are: %s" % (name, ", ".join(available)))

Exception Type: FieldError at /password/reset/ Exception Value: Cannot resolve keyword 'is_active' into field. Choices are: Profile, Profile_id, active, admin, date_joined, email, emailaddress, favorites_count, follower_count, followers, following_count, id, last_login, logentry, password, points_count, questions_count, socialaccount, staff, targets, username

When I remove the form_class from the view and use the default form, it works correctly. Why is it not working when I add the custom form?

1
Nowhere do you show something with is_active...Willem Van Onsem
@WillemVanOnsem the is_active is a method in the User model to check whether or not the user is active. active is a boolean field in User. Other than that, I don't use is_active anywhereuser2896120
Did you by any change changed the User model with a model that uses active instead of is_active?Willem Van Onsem
django-allauth.readthedocs.io/en/latest/configuration.html scroll to the acocunt forms header. Does this section help you?ritlew

1 Answers

1
votes

I finally figured it out. The reason why it was producing this type of error is because I was inheriting from Auth and not Allauth for forms.

forms.py

class ResetPasswordForm(PasswordResetForm):

PasswordResetForm is from Auth and not Allauth. Allauth's class name is called: ResetPasswordForm after knowing this, my result was this:

class PasswordResetForm(ResetPasswordForm):

It works correctly now and does not give me that error.