【发布时间】:2019-04-07 07:43:00
【问题描述】:
你好 Stackoverflow 社区。p>
PasswordChangeView中实现LOGOUT功能的最佳位置在哪里
我试过了
class PasswordCorrectionView(SuccessMessageMixin, LoginRequiredMixin, PasswordChangeView):
template_name = "admin/password_change.html”
form_class = PwdChgForm
def post(self, request, *args, **kwargs):
logout(request) # here
return PasswordChangeView.post(self, request, *args, **kwargs)
但它会上升:
NotImplementedError at /account/password/change
Django doesn't provide a DB representation for AnonymousUser.
这是合理的,因为我无论如何都无法保存 AnonymousUser 密码。
所以问题是在 PasswordChangeView 中最好覆盖什么方法???
或第二个选项覆盖表单中的某些方法:
class PwdChgForm(PasswordChangeForm):
def save(self, commit=True):
self.user.is_activated = False
user_registrated.send(PwdChgForm, instance=self.user) # signal to the email sender
PasswordChangeForm.save(self, commit=True)
我需要用户在他更改密码后注销(然后通过电子邮件等确认)所有这些工作除了注销之外
【问题讨论】:
标签: django django-views django-authentication