Sanic: Catch-All URL

Created on 18 May 2018  ·  1Comment  ·  Source: sanic-org/sanic

is it possible to create catch-all url similar to flask with sanic?

from flask import Flask
app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
    return 'You want path: %s' % path

if __name__ == '__main__':
    app.run()

Most helpful comment

I was able to create catch-all url with sanic

from sanic import Sanic, request
from sanic.response import text

app = Sanic(__name__)

@app.route('/')
@app.route('/<path:path>')
async def catch_all(request, path=''):
    return text('You want path: %s' % path)

if __name__ == '__main__':
    app.run()

>All comments

I was able to create catch-all url with sanic

from sanic import Sanic, request
from sanic.response import text

app = Sanic(__name__)

@app.route('/')
@app.route('/<path:path>')
async def catch_all(request, path=''):
    return text('You want path: %s' % path)

if __name__ == '__main__':
    app.run()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olalonde picture olalonde  ·  3Comments

graingert picture graingert  ·  3Comments

rainyear picture rainyear  ·  3Comments

ZeeRoc picture ZeeRoc  ·  3Comments

misakar picture misakar  ·  4Comments