更改基于django类的视图所寻找的默认模型字段名称

时间:2018-07-16 15:25:55

标签: python django django-authentication

我正在使用PasswordResetView(Django 2.0中基于类的视图)在我的应用程序中实现“忘记密码”功能。我是基于类的视图的新手,默认情况下,它在我的用户模型中寻找is_active。但是,我覆盖了默认的用户模型,而我的模型却包含名称为active的字段。如何更改此行为?

FieldError at /account/reset-Password/
Cannot resolve keyword 'is_active' into field. Choices are: active, admin, confirm, email, full_name, id, last_login, logentry, password, social_auth, staff, timestamp, userlogin, username
Request Method: POST
Request URL:    http://127.0.0.1:8000/account/reset-Password/
Django Version: 2.0.5
Exception Type: FieldError
Exception Value:    
Cannot resolve keyword 'is_active' into field. Choices are: active, admin, confirm, email, full_name, id, last_login, logentry, password, social_auth, staff, timestamp, userlogin, username
Exception Location: /home/yash/Desktop/ltigo/lib/python3.6/site-packages/django/db/models/sql/query.py in names_to_path, line 1379
Python Executable:  /home/yash/Desktop/ltigo/bin/python
Python Version: 3.6.5
Python Path:    
['/home/yash/Desktop/ltigo/src',
 '/home/yash/Desktop/ltigo',
 '/home/yash/Desktop/ltigo/lib/python36.zip',
 '/home/yash/Desktop/ltigo/lib/python3.6',
 '/home/yash/Desktop/ltigo/lib/python3.6/lib-dynload',
 '/usr/lib/python3.6',
 '/home/yash/Desktop/ltigo/lib/python3.6/site-packages',
 '/snap/pycharm-professional/68/helpers/pycharm_matplotlib_backend']
Server time:    Mon, 16 Jul 2018 15:18:07 +0000

1 个答案:

答案 0 :(得分:0)

要解决该特定错误,似乎必须将PasswordResetForm子类化,以使其不使用is_active。然后在密码重设视图中使用您的表单。

但是,我建议您不要将该字段重命名为active-可能还会在其他地方引起问题。