龙卷风无法获取网址中的参数

时间:2019-07-04 09:00:05

标签: python swagger tornado swagger-2.0

我有一个内置于Tornado中的API,我正尝试使用tornado-swirl对其进行文档化。由于某种原因,它无法从定义的URL中选择可选的查询参数。如何解决呢?我不确定自己在做什么错,或者我在这里错过了什么。

我已经更改了模式,甚至使用了 docstut

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的方式有关。

1 个答案:

答案 0 :(得分:2)

您只需要在文档字符串中告知path参数,就像这样:

"""Item

Creating a new item

Path Params:
    id (string) --  Your id

Tags:
    Item
"""