为了账号安全,请及时绑定邮箱和手机立即绑定

注销反向网址不适用于下一页

注销反向网址不适用于下一页

慕姐4208626 2023-02-15 15:04:30
在我看来,我正在检查拥有特定电子邮件地址的用户是否是经过身份验证的用户。如果没有,我想重定向到注销,然后使用相同的 URL 登录。这是我的观点:class VerifyUserEmailAddressView(LoginRequiredMixin, SingleObjectMixin, generic.View):    model = UserEmailAddress    success_url = reverse_lazy('accounts:edit_profile_emails')    def get(self, request, *args, **kwargs):        email_address = self.get_object()        if (not (email_address.user == self.request.user)):            return redirect(to='accounts:logout', **{'next_page': self.request.get_full_path()}) # This is the line that causes the exception.        assert (email_address.user == self.request.user)        ...这是我的注销视图:class LogoutView(django_auth_views.LogoutView):    template_name = 'accounts/logged_out.html'但问题是,我得到一个例外:django.urls.exceptions.NoReverseMatch: Reverse for 'logout' with keyword arguments '{'next_page': '/edit-profile/emails/95209103364882328130/verify/64435189922652686051/'}' not found. 1 pattern(s) tried: ['logout\\/$']urls.py:urlpatterns = [    path(route='login/', view=views.LoginView.as_view(), name='login'),    path(route='logout/', view=views.LogoutView.as_view(), name='logout'),    path(route='edit-profile/emails/', view=views.EditProfileEmailsView.as_view(), name='edit_profile_emails'),    path(route='edit-profile/emails/<digits:pk>/verify/<str:token>/', view=views.VerifyUserEmailAddressView.as_view(), name='verify_email'),]我该如何解决这个问题?
查看完整描述

1 回答

?
噜噜哒

TA贡献1784条经验 获得超7个赞

我假设next_page是URL 查询参数而不是URL 参数


如果是这样,您必须生成一个类似于以下内容的 URL,


/account/logout/?next=/foo/bar/somewhere/

为此,请将您的重定向语句替换为,


from django.urls import reverse


return redirect('{}?next={}'.format(reverse('accounts:logout'), self.request.get_full_path()))



查看完整回答
反对 回复 2023-02-15
  • 1 回答
  • 0 关注
  • 114 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号