在我看來,我正在檢查擁有特定電子郵件地址的用戶是否是經(jīng)過身份驗證的用戶。如果沒有,我想重定向到注銷,然后使用相同的 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貢獻(xiàn)1784條經(jīng)驗 獲得超7個贊
我假設(shè)next_page是URL 查詢參數(shù)而不是URL 參數(shù)
如果是這樣,您必須生成一個類似于以下內(nèi)容的 URL,
/account/logout/?next=/foo/bar/somewhere/
為此,請將您的重定向語句替換為,
from django.urls import reverse
return redirect('{}?next={}'.format(reverse('accounts:logout'), self.request.get_full_path()))
添加回答
舉報
0/150
提交
取消