结合 web2py 身份验证装饰器
Combining web2py authentication decorators
在 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)
在@auth.requires
里面,必须用auth.has_permission
,不能用auth.requires_permission
(后者是装饰器)
在 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)
在@auth.requires
里面,必须用auth.has_permission
,不能用auth.requires_permission
(后者是装饰器)