0

I am trying to create catch-all-url route in quart similar to what we have in flask, but the route is not working as expected.

Flask:

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

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

Quart:

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

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

Error:

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'
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
thotam
  • 941
  • 2
  • 16
  • 31

1 Answers1

0

This was asked on the Quart github repository, it is a bug in Quart that has been fixed. The approach given here is correct. Note I am the Quart author.

pgjones
  • 6,044
  • 1
  • 14
  • 12