Ticket #5394: authentication-docs.diff
File authentication-docs.diff, 1.3 KB (added by , 17 years ago) |
---|
-
docs/authentication.txt
402 402 def my_view(request): 403 403 # ... 404 404 405 ``login_required`` also takes an optional ``redirect_field_name`` parameter. Example:: 406 407 from django.contrib.auth.decorators import login_required 408 409 def my_view(request): 410 # ... 411 my_view = login_required(redirect_field_name='redirect_to')(my_view) 412 413 Again, an equivalent example of the more compact decorator syntax introduced in Python 2.4:: 414 415 from django.contrib.auth.decorators import login_required 416 417 @login_required(redirect_field_name='redirect_to') 418 def my_view(request): 419 # ... 420 405 421 ``login_required`` does the following: 406 422 407 423 * If the user isn't logged in, redirect to ``settings.LOGIN_URL`` 408 424 (``/accounts/login/`` by default), passing the current absolute URL 409 in the query string as ``next``. For example: 425 in the query string as ``next`` or the value of ``redirect_field_name``. 426 For example: 410 427 ``/accounts/login/?next=/polls/3/``. 411 428 * If the user is logged in, execute the view normally. The view code is 412 429 free to assume the user is logged in.