Fixed #28131 -- Corrected examples of using attribute lookups on the "perms" template variable.

This commit is contained in:
Botond Beres 2017-10-27 18:02:26 +01:00 committed by Tim Graham
parent 73241132f2
commit 51d7feff87
1 changed files with 10 additions and 11 deletions

View File

@ -1537,21 +1537,20 @@ The currently logged-in user's permissions are stored in the template variable
``django.contrib.auth.context_processors.PermWrapper``, which is a ``django.contrib.auth.context_processors.PermWrapper``, which is a
template-friendly proxy of permissions. template-friendly proxy of permissions.
In the ``{{ perms }}`` object, single-attribute lookup is a proxy to Evaluating a single-attribute lookup of ``{{ perms }}`` as a boolean is a proxy
:meth:`User.has_module_perms <django.contrib.auth.models.User.has_module_perms>`. to :meth:`User.has_module_perms()
This example would display ``True`` if the logged-in user had any permissions <django.contrib.auth.models.User.has_module_perms>`. For example, to check if
in the ``foo`` app:: the logged-in user has any permissions in the ``foo`` app::
{{ perms.foo }} {% if perms.foo %}
Two-level-attribute lookup is a proxy to Evaluating a two-level-attribute lookup as a boolean is a proxy to
:meth:`User.has_perm <django.contrib.auth.models.User.has_perm>`. This example :meth:`User.has_perm() <django.contrib.auth.models.User.has_perm>`. For example,
would display ``True`` if the logged-in user had the permission to check if the logged-in user has the permission ``foo.can_vote``::
``foo.can_vote``::
{{ perms.foo.can_vote }} {% if perms.foo.can_vote %}
Thus, you can check permissions in template ``{% if %}`` statements: Here's a more complete example of checking permissions in a template:
.. code-block:: html+django .. code-block:: html+django