Catch-All URL in quart

时间:2018-05-08 12:59:18

标签: flask quart

我正在尝试以夸脱方式创建catch-all-url路线,类似于我们在烧瓶中的路线,但路线未按预期工作。

烧瓶中:

from flask import Flask, request
app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
  return 'Hello World'

夸脱:

from quart import Quart, request
app = Quart(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
async def index(path):
  return 'Hello World'

错误:

Running on http://0.0.0.0:5000 (CTRL + C to quit)
[2018-05-08 08:53:54,109] ERROR in app: Exception on request GET /
Traceback (most recent call last):
 File "/usr/local/lib/python3.6/site-packages/quart/app.py", line 1303, in handle_request
   return await self.full_dispatch_request(request_context)
 File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
 return self.gen.send(None)
 File "/usr/local/lib/python3.6/site-packages/quart/app.py", line 1325, in full_dispatch_request
 result = await self.handle_user_exception(error)
 File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
return self.gen.send(None)
File "/usr/local/lib/python3.6/site-packages/quart/app.py", line 819, in handle_user_exception
raise error
File "/usr/local/lib/python3.6/site-packages/quart/app.py", line 1323, in full_dispatch_request
result = await self.dispatch_request(request_context)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
return self.gen.send(None)
File "/usr/local/lib/python3.6/site-packages/quart/app.py", line 1371, in dispatch_request
return await handler(**request_.view_args)
TypeError: index() missing 1 required positional argument: 'path'

1 个答案:

答案 0 :(得分:0)

这是在Quart github repository上询问的,这是Quart中的一个错误已被修复。这里给出的方法是正确的。注意我是Quart的作者。