0

我正在尝试在 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'
4

1 回答 1

0

这是在 Quart github存储库上提出的,这是 Quart 中的一个错误,已修复。这里给出的方法是正确的。注意我是 Quart 作者。

于 2018-05-08T18:00:07.100 回答