I've created a custom permission on one of my models and I've given a
user the custom permission.
When I go into the shell (manage.py shell), I can confirm that the
user has the custom permission. But when I use the perms object in one
of my templates, it simple doesn't work.
{% if perms.custom_perm %}
do something
{% endif %}
According to the documentation, the perms object is included in the
template language. So I assume I don't have to create the object and
pass it to my template?
I've even tried the fix posted here http://code.djangoproject.com/ticket/2418
but to no avail. I still can't use the perms object in my template.
I've got the same problem. From the shell:
>>> user = User.objects.get(id = 3)
>>> user.get_all_permissions()
Set(['ivms.can_play'])
>>> user.has_perm('ivms.can_play')
True
Fantastic. When I try and access it via my template it doesn't work.
e.g.
{% if perms.ivms.can_play %}
I have permissions
{% else %}
I don't have permissions
{% endif %}
Do I need to load any template tags to access this tag?
Note that I'm still using 0.95.
Thanks,
Ben
On Mar 13, 12:02 am, "masuran" <michael.ancka...@gmail.com> wrote:
> Hello everyone,
>
> I've created a custom permission on one of my models and I've given a
> user the custom permission.
>
> When I go into the shell (manage.py shell), I can confirm that the
> user has the custom permission. But when I use thepermsobject in one
> of my templates, it simple doesn't work.
>
> {% ifperms.custom_perm %}
> do something
> {% endif %}
>
> According to the documentation, thepermsobject is included in thetemplatelanguage. So I assume I don't have to create the object and
> pass it to mytemplate?
> I've even tried the fix posted herehttp://code.djangoproject.com/ticket/2418
Here's how you do it. In your view
from django.template import RequestContext
return render_to_response("mytemplate.html",
context_instance=RequestContext(request))
Works for me!