Search code examples
pythonflaskurl-routingwerkzeug

Flask: why having path converter in root route doesn't work?


from flask import Flask, render_template

app = Flask(__name__, static_url_path='')

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/page/<path:page>')
def article(page):
    return render_template('page.html')

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

Work just fine. But if i change the second route to @app.route('/<path:page>'), then any access to URL like /path/to/page yields 404.

Why doesn't @app.route('/<path:page>') work?

Related questions, that don't answer the question however:


Solution

  • static_url_path conflicts with routing. Flask thinks that path after / is reserved for static files, therefore path converter didn't work. See: URL routing conflicts for static files in Flask dev server