更改基于 django class 的视图查找的默认模型字段名称
Changing a default model field name that django class based views look for
我正在使用 PasswordResetView
(Django 2.0 中基于 class 的视图)在我的应用程序中实现忘记密码功能。我是基于 class 的视图的新手,默认情况下它会在我的用户模型中查找 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
要修复该特定错误,看起来您必须继承 PasswordResetForm
以便它不使用 is_active
。然后在您的密码重置视图中使用您的表单。
但是,我建议不要将字段重命名为 active
- 这也可能在其他地方引起问题。
我正在使用 PasswordResetView
(Django 2.0 中基于 class 的视图)在我的应用程序中实现忘记密码功能。我是基于 class 的视图的新手,默认情况下它会在我的用户模型中查找 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
要修复该特定错误,看起来您必须继承 PasswordResetForm
以便它不使用 is_active
。然后在您的密码重置视图中使用您的表单。
但是,我建议不要将字段重命名为 active
- 这也可能在其他地方引起问题。