mirror of https://github.com/django/django.git
Unified LoginView/LogoutView.get_default_redirect_url() methods.
This might change the behavior when self.next_page == "". However, resolve_url(self.next_page) would almost certainly fail in that case. It is technically possible to define a logout URLpattern whose name is "": path('logout/', LogoutView.as_view(), name=''), and then to refer to this pattern with next_page = "". However this feels like a pathological case, so we decided not to handle it. Most checks on next_page, LOGIN_REDIRECT_URL, and LOGOUT_REDIRECT_URL are performed with boolean evaluation rather than comparison with None. That's why we standardizing that way.
This commit is contained in:
parent
5b8699e723
commit
5fcd9b8c33
|
@ -85,7 +85,10 @@ class LoginView(RedirectURLMixin, FormView):
|
||||||
|
|
||||||
def get_default_redirect_url(self):
|
def get_default_redirect_url(self):
|
||||||
"""Return the default redirect URL."""
|
"""Return the default redirect URL."""
|
||||||
return resolve_url(self.next_page or settings.LOGIN_REDIRECT_URL)
|
if self.next_page:
|
||||||
|
return resolve_url(self.next_page)
|
||||||
|
else:
|
||||||
|
return resolve_url(settings.LOGIN_REDIRECT_URL)
|
||||||
|
|
||||||
def get_form_class(self):
|
def get_form_class(self):
|
||||||
return self.authentication_form or self.form_class
|
return self.authentication_form or self.form_class
|
||||||
|
@ -151,13 +154,17 @@ class LogoutView(RedirectURLMixin, TemplateView):
|
||||||
# RemovedInDjango50Warning.
|
# RemovedInDjango50Warning.
|
||||||
get = post
|
get = post
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_default_redirect_url(self):
|
||||||
if self.next_page is not None:
|
"""Return the default redirect URL, or None if no URL is configured."""
|
||||||
next_page = resolve_url(self.next_page)
|
if self.next_page:
|
||||||
|
return resolve_url(self.next_page)
|
||||||
elif settings.LOGOUT_REDIRECT_URL:
|
elif settings.LOGOUT_REDIRECT_URL:
|
||||||
next_page = resolve_url(settings.LOGOUT_REDIRECT_URL)
|
return resolve_url(settings.LOGOUT_REDIRECT_URL)
|
||||||
else:
|
else:
|
||||||
next_page = self.next_page
|
return None
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
next_page = self.get_default_redirect_url()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self.redirect_field_name in self.request.POST
|
self.redirect_field_name in self.request.POST
|
||||||
|
|
Loading…
Reference in New Issue