Template tags¶
django-guardian
template tags. To use in a template just put the following
load tag inside a template:
{% load guardian_tags %}
get_obj_perms¶
Returns a list of permissions (as
codename
strings) for a givenuser
/group
andobj
(Model instance).Parses
get_obj_perms
tag which should be in format:{% get_obj_perms user/group for obj as "context_var" %}
Note
Make sure that you set and use those permissions in same template block (
{% block %}
).Example of usage (assuming
flatpage
andperm
objects are available from context):{% get_obj_perms request.user for flatpage as "flatpage_perms" %} {% if "delete_flatpage" in flatpage_perms %} <a href="/pages/delete?target={{ flatpage.url }}">Remove page</a> {% endif %}
Note
Please remember that superusers would always get full list of permissions for a given object.
New in version 1.2.
As of v1.2, passing
None
asobj
for this template tag won’t rise obfuscated exception and would return empty permissions set instead.