我是Django的新手。 我正在开发一个Web应用程序项目,并希望在我的项目中使用setpassword表单,该表单允许管理员重置用户密码而无需使用其旧密码。 我使用自定义用户模型(CustomUser)。 当我运行此部分时,结果如下:
请求方法:GET 要求网址:http://127.0.0.1:8000/account/1/changepass/ Django版本:2.2.1 异常类型:AssertionError
urls.py: ...
path('<int:pk>/changepass/',AdminChangeUserPassView.as_view(), name='change_password_user'),
views.py:
...
class AdminChangeUserPassView(PasswordResetConfirmView):
model = CustomUser
form_class = SetPasswordForm
template_name = 'change_password_user.html'
login_url = 'login'
success_url = reverse_lazy('user_list')
forms.py: ...
class AdminChangeUserPassForm(SetPasswordForm):
class Meta:
model = CustomUser
fields = ('new_password1','new_password2')
我在做什么错了?
完整的TraceBack:
Traceback Switch to copy-and-paste view
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\core\handlers\exception.py in inner
response = get_response(request) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\core\handlers\base.py in _get_response
response = self.process_exception_by_middleware(e, request) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\core\handlers\base.py in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\views\generic\base.py in view
return self.dispatch(request, *args, **kwargs) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\contrib\auth\mixins.py in dispatch
return super().dispatch(request, *args, **kwargs) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\utils\decorators.py in _wrapper
return bound_method(*args, **kwargs) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\views\decorators\debug.py in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\utils\decorators.py in _wrapper
return bound_method(*args, **kwargs) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\views\decorators\cache.py in _wrapped_view_func
response = view_func(request, *args, **kwargs) …
▶ Local vars
C:\Users\Administrator\.virtualenvs\SrvInfoProject-iXAvv7aw\lib\site-packages\django\contrib\auth\views.py in dispatch
assert 'uidb64' in kwargs and 'token' in kwargs …
▶ Local vars