Skip to content

Instantly share code, notes, and snippets.

@berend
Created August 28, 2018 15:41
Show Gist options
  • Save berend/393b3a6e887b5f170a8e267837b53ec5 to your computer and use it in GitHub Desktop.
Save berend/393b3a6e887b5f170a8e267837b53ec5 to your computer and use it in GitHub Desktop.
#
from flask import Blueprint
from flask import Flask
app = Flask(__name__)
v1 = Blueprint("version1", "version1", url_prefix="/v1")
v2 = Blueprint('version2', "version2", url_prefix="/v2")
@v2.route("/foo")
def index():
return "v2 foo looks different than v1"
@v1.route("/foo")
def index():
return "v1 foo looks different than v2"
@v2.route("/bar")
@v1.route("/bar")
def hello():
return "bar stays the same for v1 and v2"
@app.route('/get_rules')
def root():
rules = [str(rule) for rule in app.url_map.iter_rules()]
return "\n".join(rules)
app.register_blueprint(v1, url_prefix="/v1")
app.register_blueprint(v2, url_prefix="/v2")
app.register_blueprint(v2, url_prefix="/")
app.run(port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment