summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-08-12 14:15:41 +0000
committerJannis Leidel <jannis@leidel.info>2011-08-12 14:15:41 +0000
commit351d5da69b994c2e390f8d33e66ce5836b0bf348 (patch)
tree3505bde3aaab890e6dfe65451ae6c50fcd474e46 /docs
parent1ca6e9b9e24240033349c93b05902c79c0a25bbb (diff)
Fixed #4617 -- Added `raise_exception` option to `permission_required` decorator to be able to raise a PermissionDenied exception instead of redirecting to the login page.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16607 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/auth.txt13
1 files changed, 11 insertions, 2 deletions
diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
index a50e24c0df..9df2d11115 100644
--- a/docs/topics/auth.txt
+++ b/docs/topics/auth.txt
@@ -1167,7 +1167,7 @@ checks to make sure the user is logged in and has the permission
return HttpResponse("You can't vote in this poll.")
# ...
-.. function:: user_passes_test()
+.. function:: user_passes_test(func, [login_url=None])
As a shortcut, you can use the convenient ``user_passes_test`` decorator::
@@ -1205,7 +1205,7 @@ checks to make sure the user is logged in and has the permission
The permission_required decorator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. function:: permission_required()
+.. function:: permission_required([login_url=None, raise_exception=False])
It's a relatively common task to check whether a user has a particular
permission. For that reason, Django provides a shortcut for that case: the
@@ -1234,6 +1234,13 @@ The permission_required decorator
As in the :func:`~decorators.login_required` decorator, ``login_url``
defaults to :setting:`settings.LOGIN_URL <LOGIN_URL>`.
+ .. versionchanged:: 1.4
+
+ Added ``raise_exception`` parameter. If given, the decorator will raise
+ :exc:`~django.core.exceptions.PermissionDenied`, prompting
+ :ref:`the 403 (HTTP Forbidden) view<http_forbidden_view>` instead of
+ redirecting to the login page.
+
.. currentmodule:: django.contrib.auth
Limiting access to generic views
@@ -1632,6 +1639,8 @@ the ``auth_permission`` table most of the time.
.. _django/contrib/auth/backends.py: http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/backends.py
+.. _anonymous_auth:
+
Authorization for anonymous users
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~