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

eseglem picture eseglem  路  4Comments

ZeeRoc picture ZeeRoc  路  3Comments

geekpy picture geekpy  路  4Comments

litelife picture litelife  路  3Comments

woutor picture woutor  路  3Comments