我需要檢查每個認證用戶所需的權限使用Django和Python。我在下面解釋我的代碼。如何根據使用Django和Python的已認證用戶檢查權限
class Permission(models.Model):
"""docstring for Permission"""
user_id = models.ForeignKey(User)
class Meta:
permissions = (
("view_reactor", "1"),
("find_reactor", "1"),
("controll_reactor", "0"),
)
Views.py:
from django.contrib.auth.decorators import permission_required
def view_reactor(request):
""" This function for to get serch screen. """
return render(request, 'plant/view_reactor.html',
{'count': 1})
在這裏,我需要檢查@permission_required
裝飾功能按適當userid
。假設登錄的用戶有權限("view_reactor", "1"),
那麼view_reactor
函數可以訪問,如果("view_reactor", "0")
那麼它不能被訪問。
? meta當然不能存儲這些東西。你必須有一個類變量來存儲權限,然後檢查 –
你可以根據我的要求通過一篇文章分享你的想法嗎? – satya
[This](https://ghrhome.gitbooks.io/djangoknowhow/using_the_django_authentication_system/the_permission_required_decorator。HTML)可能會幫助你 –