在django模板中检查权限不工作 [英] Checking for permission in django template not working
问题描述
我想在模板中验证用户权限。如果用户有权限,他/她将能够访问该模板。在写下面的代码后,我授予用户权限,当我查看该页面时,它将落在 {%else%}
语句。显示用户没有权限。我该怎么做?
I want to verify user permission in template. If a user has permission he/she will be able to access the template. After writing the below code and I granted the user permission, when I view the page it will fall on the {% else %}
statement. showing that the user don't have permission. How can I go about this?
#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 %}
推荐答案
你是否在你的模板中传递烫发?
您是否在您的视图或管理界面中显式设置了perms.paid.can_view_film?
用户是否具有perms.paid.can_view_film权限的组的一部分?
Are you passing perms in your template? Are you setting perms.paid.can_view_film either explicitly in your view or via the admin interface? Is the user a part of a group that has the perms.paid.can_view_film permission?
您确定应用程序名称是付费吗?这应该是应用程序名称,而不是模型名称。
Are you sure the app name is 'paid'? That's supposed to be the app name, not the model name.
这篇关于在django模板中检查权限不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!