1
I’ve done something like you’re asking. Adapting what I’ve done to your case, you’d have in the view:
template = loader.get_template('foo/foo.html')
context = RequestContext(
request,
{
'can_view': request.user.has_perm('tracking.view_visitor')),
})
return HttpResponse(template.render(context))
In the template:
{% if can_view %}
<!-- whatever you need -->
{% endif %}
1
Well, you can do something like :
extra_context = {}
if request.user.has_perm('tracking.view_visitor'):
extra_context['show_links'] = True
else:
pass
And in your template , you can check it with :
{% if show_links %}
display htmls or links
{% endif %}
Make sure to pass context while rendering .
Source:stackexchange.com