Check if a user has a permission in pyramid (pylons 2)?

前端 未结 1 1091
臣服心动
臣服心动 2020-12-19 21:56

How do i check if a user has a permission in pyramid. For example, I want to show some HTML only if a user has some permission, but have the view available for everybody.

相关标签:
1条回答
  • 2020-12-19 22:02

    The usual method is:

    from pyramid.security import has_permission
    has_permission('view', someresource, request)
    

    See also http://docs.pylonsproject.org/projects/pyramid/1.0/narr/security.html#debugging-imperative-authorization-failures and http://docs.pylonsproject.org/projects/pyramid/1.0/api/security.html#pyramid.security.has_permission

    0 讨论(0)
提交回复
热议问题