Reputation: 387
I am using the catch-all url pattern in my Flask route. I want the view to ignore (throw a 404 error) any path that starts with /api
. How can I do this?
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
return 'Hello, World!'
Upvotes: 22
Views: 18923
Reputation: 127200
Check if the path starts with the prefix, then abort if it does.
from flask import abort
if path.startswith('api'):
abort(404)
Upvotes: 49