I’ve been hitting an issue trying to get Sanic request parameters working, which it turns out is due to the fact I’m using
app.static() at the same time. This appears to be https://github.com/huge-success/sanic/issues/1543, which went stale without being addressed. I’d suggest this should probably be reopened, if people agree there’s an issue here.
I’ve narrowed it down to the following example:
import sanic, sanic.request, sanic.response app = sanic.app.Sanic() app.static("/", "./static") @app.route("/") @app.route("/<param>") async def route(req, param=None): return sanic.response.text(param if param else "homepage") app.run(port=3333)
The above gives a “file not found” error when navigating to
http://<baseurl>/foo, since it’s looking for a file called “foo”, and fails to fall back on the parameter match
A workaround is to have the
app.static("/", "./static") line come after the ‘route’ definition, i.e. after
"/<param>" has been added as a route. It feels like the order shouldn’t matter here though!
Seen on Sanic 19.3.1 and 20.6.3.