public
Last active

flask dynamic url_prefix for blueprints

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
from flask import Flask, Blueprint, request
 
## blueprint ##################################################################
 
bp = Blueprint('category_functionality', __name__)
 
@bp.route('/')
def index(category):
return "this is the index page for %r" % category
 
@bp.route('/list')
def list(category):
return "return a list of %r" % category
 
## app ########################################################################
 
app = Flask(__name__)
app.config['DEBUG'] = True
app.register_blueprint(bp, url_prefix="/<path:category>")
 
@app.route("/")
def index():
return "index"
 
if __name__ == "__main__":
app.run(use_debugger=True, use_reloader=True)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.