在db.py中
articles_service = Service()
在controller.py
中def call():
"""
exposes services. for example:
http://..../[app]/articles/call/jsonrpc
decorate with @services.jsonrpc the functions to expose
supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
"""
return articles_service()
@articles_service.json
def article_search():
# do something with request.post_vars
对app/controller/article_search
进行URL调用将引发:
TypeError: article_search() takes no arguments (1 given)
这是在将Web2py从web2py v2.14.6
升级到v2.18.2
我想我也许是依赖于早期的Web2py版本中的一个错误,此错误已被关闭。
如果我将参数添加到控制器函数中,例如def article_search(param)
,则会引发异常:
TypeError: article_search() got an unexpected keyword argument
,后接字典(保留request.post_vars)。
完整的堆栈跟踪:
Traceback (most recent call last):
File "/base/data/home/apps/e~jupiter1351/t1.416461603777157393/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/base/data/home/apps/e~jupiter1351/t1.416461603777157393/applications/jupiter/controllers/articles.py", line 115, in <module>
File "/base/data/home/apps/e~jupiter1351/t1.416461603777157393/gluon/globals.py", line 421, in <lambda>
self._caller = lambda f: f()
File "/base/data/home/apps/e~jupiter1351/t1.416461603777157393/applications/jupiter/controllers/articles.py", line 114, in call
return articles_service()
File "/base/data/home/apps/e~jupiter1351/t1.416461603777157393/gluon/tools.py", line 5366, in __call__
return self.serve_json(request.args[1:])
File "/base/data/home/apps/e~jupiter1351/t1.416461603777157393/gluon/tools.py", line 5050, in serve_json
s = self.call_service_function(self.json_procedures[args[0]], *args[1:], **d)
File "/base/data/home/apps/e~jupiter1351/t1.416461603777157393/gluon/tools.py", line 5391, in call_service_function
return f(*a, **b)
TypeError: article_search() takes no arguments (1 given)