在 PasswordChangeView 中实现 "LOGOUT" 函数的正确位置在哪里?
Where is the proper place to implement "LOGOUT" function in PasswordChangeView?
你好 Whosebug 社区。
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)
我需要用户在更改密码后注销(然后通过电子邮件等确认)所有这些工作除了注销
改变这个
def post(self, request, *args, **kwargs):
logout(request) # here
return PasswordChangeView.post(self, request, *args, **kwargs)
至
def post(self, request, *args, **kwargs):
PasswordChangeView.post(self, request, *args, **kwargs)
logout(request) # here
return redirect('your-login-url')
你好 Whosebug 社区。
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)
我需要用户在更改密码后注销(然后通过电子邮件等确认)所有这些工作除了注销
改变这个
def post(self, request, *args, **kwargs):
logout(request) # here
return PasswordChangeView.post(self, request, *args, **kwargs)
至
def post(self, request, *args, **kwargs):
PasswordChangeView.post(self, request, *args, **kwargs)
logout(request) # here
return redirect('your-login-url')