Code

Ticket #5394: authentication-docs.diff

File authentication-docs.diff, 1.3 KB (added by DavidReynolds, 7 years ago)

update authentication docs

Line 
1Index: docs/authentication.txt
2===================================================================
3--- docs/authentication.txt     (revision 6186)
4+++ docs/authentication.txt     (working copy)
5@@ -402,11 +402,28 @@
6     def my_view(request):
7         # ...
8 
9+``login_required`` also takes an optional ``redirect_field_name`` parameter. Example::
10+   
11+    from django.contrib.auth.decorators import login_required
12+
13+    def my_view(request):
14+        # ...
15+    my_view = login_required(redirect_field_name='redirect_to')(my_view)
16+
17+Again, an equivalent example of the more compact decorator syntax introduced in Python 2.4::
18+   
19+    from django.contrib.auth.decorators import login_required
20+
21+    @login_required(redirect_field_name='redirect_to')
22+    def my_view(request):
23+        # ...
24+
25 ``login_required`` does the following:
26 
27     * If the user isn't logged in, redirect to ``settings.LOGIN_URL``
28       (``/accounts/login/`` by default), passing the current absolute URL
29-      in the query string as ``next``. For example:
30+      in the query string as ``next`` or the value of ``redirect_field_name``.
31+      For example:
32       ``/accounts/login/?next=/polls/3/``.
33     * If the user is logged in, execute the view normally. The view code is
34       free to assume the user is logged in.