diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2022-04-16 19:36:59 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-04-20 10:04:29 +0200 |
| commit | 5fcd9b8c3383e2ab20c1573b44131105654b99d0 (patch) | |
| tree | a8f8cb9c775436c6243e78d9c216855b5cadfe6a | |
| parent | 5b8699e723d9daf373fff46c6859fed2b780a9bd (diff) | |
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.
| -rw-r--r-- | django/contrib/auth/views.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index 25d987d0dc..60ae71b669 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -85,7 +85,10 @@ class LoginView(RedirectURLMixin, FormView): def get_default_redirect_url(self): """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): return self.authentication_form or self.form_class @@ -151,13 +154,17 @@ class LogoutView(RedirectURLMixin, TemplateView): # RemovedInDjango50Warning. get = post - def get_success_url(self): - if self.next_page is not None: - next_page = resolve_url(self.next_page) + def get_default_redirect_url(self): + """Return the default redirect URL, or None if no URL is configured.""" + if self.next_page: + return resolve_url(self.next_page) elif settings.LOGOUT_REDIRECT_URL: - next_page = resolve_url(settings.LOGOUT_REDIRECT_URL) + return resolve_url(settings.LOGOUT_REDIRECT_URL) else: - next_page = self.next_page + return None + + def get_success_url(self): + next_page = self.get_default_redirect_url() if ( self.redirect_field_name in self.request.POST |
