【问题标题】:Combining web2py authentication decorators结合 web2py 身份验证装饰器
【发布时间】:2015-04-21 06:54:14
【问题描述】:

在 web2py 中,我试图将两个身份验证装饰器组合到一个方法中。

@auth.requires_permission('read', 'inv_header')
@auth.requires_permission('read', 'inv_detail')

我的理解是这样的:

@auth.requires(auth.requires_permission('read', 'inv_header') and \
auth.requires_permission('read', 'inv_detail'))

但我收到此错误。

Traceback (most recent call last):
  File "/opt/web-apps/web2py/gluon/restricted.py", line 224, in restricted
    exec ccode in environment
  File "/opt/web-apps/web2py/applications/niptview/controllers/batch.py", line 317, in <module>
  File "/opt/web-apps/web2py/gluon/globals.py", line 393, in <lambda>
    self._caller = lambda f: f()
  File "/opt/web-apps/web2py/gluon/tools.py", line 3437, in f
    flag = condition()
TypeError: decorator() takes exactly 1 argument (0 given)

web2py™ 版本 2.9.12-stable+timestamp.2015.01.17.06.11.03 Python Python 2.7.5:/usr/bin/python(前缀:/usr)

我有什么遗漏的吗?

我的环境如下:

web2py™ Version 2.9.12-stable+timestamp.2015.01.17.06.11.03
Python  Python 2.7.5: /usr/bin/python (prefix: /usr)

【问题讨论】:

    标签: python web2py


    【解决方案1】:

    @auth.requires内部,必须使用auth.has_permission,而不是auth.requires_permission(后者是装饰器)。

    【讨论】:

    猜你喜欢
    • 2019-07-02
    • 2015-10-23
    • 1970-01-01
    • 2013-11-03
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 2013-10-31
    相关资源
    最近更新 更多