我想在模板中验证用户权限,如果用户有权限,他/她将能够访问该模板。在编写以下代码并授予用户权限后,当我查看页面时,它会落在{% else %}
语句上,显示用户没有权限。我该怎么做?
#CREATED A GROUP IN DJANGO ADMIN CALLED 'Premium'
Class Paid(models.Model):
#models here
class Meta:
permissions=(
("view_film","Can view film"),
)
视图
def eyo(request):
return render_to_response('eyo.html',context_instance=RequestContext(request))
模板
{% block content %}
{% if perms.paid.can_view_film %}
<form action='https://www.test.com/checkout' method='post'>
<input name='submit' type='submit' value='Checkout' />
</form>
{% else %}
<p> yo broke! </p>
{% endif %}