0

我正在尝试按照此处的说明实现 RESTful 服务: http ://www.web2pyslices.com/slice/show/1533/restful-api-with-web2py

GET、PUT 和 POST 按预期工作,但 DELETE 没有。我明白了

 <type 'exceptions.TypeError'> not indexable

web2py™ Version 
 2.6.3-stable+timestamp.2013.09.15.17.01.20
Python  Python 2.7.4: /usr/bin/python (prefix: /usr)  
Traceback (most recent call last):  
  File "../gluon/restricted.py", line 217, in restricted  
    exec ccode in environment  
  File "../applications/app/controllers/default.py", line 103, in <module>  
  File "../gluon/globals.py", line 378, in <lambda>  
    self._caller = lambda f: f()  
  File "../gluon/globals.py", line 348, in f  
    raise e  
TypeError: not indexable

有任何想法吗?

4

2 回答 2

1

经过调试,我发现问题是由vars解析函数引起的,它抛出了异常。globals.py我在at添加了以下代码def restful(self)

if rest_action.func_name == 'DELETE':
    return  rest_action(*_self.args)

这解决了问题

于 2013-09-18T09:40:39.430 回答
0

在 web2py 中实现 RESTful 服务

@request.restful()
def API():
    response.view = 'generic.json'
    def GET(*args, **vars):
        return dict()
    def POST(*args, **vars):
        return dict()
    def DELETE(*args, **vars):
        return dict()
    def PUT(*args, **vars):
        return dict()
    return locals()
于 2021-10-11T04:30:56.780 回答