Cannot resolve keyword 'is_active' into field?

user2896120 Source

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:

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

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

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:


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

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

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

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

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

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

File "C:\python3.6.3\lib\site-packages\allauth\account\" in form_valid 639.

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

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

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

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

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

File "C:\python3.6.3\lib\site-packages\django\db\models\sql\" 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\" in _add_q 1276. allow_joins=allow_joins, split_subq=split_subq,

File "C:\python3.6.3\lib\site-packages\django\db\models\sql\" 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\" 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\" 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?



answered 4 months ago user2896120 #1

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.

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.

comments powered by Disqus