From 55d6aebfecb527d64f50e608bb51cb5ea81f4c62 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 14 Sep 2007 19:25:37 +0000 Subject: Fixed #5394 -- REDIRECT_FIELD_NAME is now configurable. Thanks, Petr Marhoun, DavidReynolds and effbot git-svn-id: http://code.djangoproject.com/svn/django/trunk@6206 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/authentication.txt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/authentication.txt b/docs/authentication.txt index 131a8930b5..820aff2712 100644 --- a/docs/authentication.txt +++ b/docs/authentication.txt @@ -402,11 +402,29 @@ introduced in Python 2.4:: def my_view(request): # ... +In the Django development version, ``login_required`` also takes an optional +``redirect_field_name`` parameter. Example:: + + from django.contrib.auth.decorators import login_required + + def my_view(request): + # ... + my_view = login_required(redirect_field_name='redirect_to')(my_view) + +Again, an equivalent example of the more compact decorator syntax introduced in Python 2.4:: + + from django.contrib.auth.decorators import login_required + + @login_required(redirect_field_name='redirect_to') + def my_view(request): + # ... + ``login_required`` does the following: * If the user isn't logged in, redirect to ``settings.LOGIN_URL`` (``/accounts/login/`` by default), passing the current absolute URL - in the query string as ``next``. For example: + in the query string as ``next`` or the value of ``redirect_field_name``. + For example: ``/accounts/login/?next=/polls/3/``. * If the user is logged in, execute the view normally. The view code is free to assume the user is logged in. -- cgit v1.3