i具有Tornado
中构建的API,我正在尝试使用tornado-swirl
进行记录。由于某种原因,它无法从定义的URL中选择可选的查询参数。如何解决?我不确定我在做什么错,或者我在这里缺少什么。
我已经更改了模式,甚至使用了文档和tut。
import tornado.web
import tornado_swirl as swirl
from .base import BaseHandler
@swirl.restapi('/item/(?P<id>[w-]+)?')
class ItemHandler(BaseHandler):
def post(self, id):
"""Item
Creating a new item
Tags:
Item
"""
# store the item
pass
async def get(self, id):
"""Item
Get items or item
Tags:
Item
"""
# return all items if no id was provided
# or return item by id when provided
pass
我会收到以下错误:
Traceback (most recent call last):
File "/Users/.../venv/lib/python3.7/site-packages/tornado/web.py", line 1697, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/Users/.../venv/lib/python3.7/site-packages/tornado_swirl/views.py", line 101, in get
for path, spec, operations in apis},
File "/Users/.../venv/lib/python3.7/site-packages/tornado_swirl/views.py", line 100, in <dictcomp>
'paths': {path: self.__get_api_spec(spec, operations)
File "/Users/.../venv/lib/python3.7/site-packages/tornado_swirl/views.py", line 368, in find_api
['{%s}' % arg for arg in [param.name for param in vals]]
TypeError: not enough arguments for format string
显然,它没有得到争论。我认为这与我在那里定义URL有关。
您只需要告知DocString中的路径参数,类似的内容:
"""Item
Creating a new item
Path Params:
id (string) -- Your id
Tags:
Item
"""