diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index f05c387c17..482e82f351 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -1339,6 +1339,26 @@ The URL where requests are redirected after login when the This is used by the :func:`~django.contrib.auth.decorators.login_required` decorator, for example. +.. _`note on LOGIN_REDIRECT_URL setting`: + +.. note:: + You can use :func:`~django.core.urlresolvers.reverse_lazy` to reference + URLs by their name instead of providing a hardcoded value. Assuming a + ``urls.py`` with an URL pattern named ``home``:: + + urlpatterns = patterns('', + url('^welcome/$', 'test_app.views.home', name='home'), + ) + + You can use :func:`~django.core.urlresolvers.reverse_lazy` like this:: + + from django.core.urlresolvers import reverse_lazy + + LOGIN_REDIRECT_URL = reverse_lazy('home') + + This also works fine with localized URLs using + :func:`~django.conf.urls.i18n.i18n_patterns`. + .. setting:: LOGIN_URL LOGIN_URL @@ -1349,6 +1369,9 @@ Default: ``'/accounts/login/'`` The URL where requests are redirected for login, especially when using the :func:`~django.contrib.auth.decorators.login_required` decorator. +.. note:: + See the `note on LOGIN_REDIRECT_URL setting`_ + .. setting:: LOGOUT_URL LOGOUT_URL @@ -1358,6 +1381,9 @@ Default: ``'/accounts/logout/'`` LOGIN_URL counterpart. +.. note:: + See the `note on LOGIN_REDIRECT_URL setting`_ + .. setting:: MANAGERS MANAGERS diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index f3e27ae1f0..f720ad3e4e 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -888,6 +888,8 @@ reverse_lazy() A lazily evaluated version of `reverse()`_. +.. function:: reverse_lazy(viewname, [urlconf=None, args=None, kwargs=None, current_app=None]) + It is useful for when you need to use a URL reversal before your project's URLConf is loaded. Some common cases where this function is necessary are: