Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Last active November 20, 2022 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbehan/80ac77006e8bf744d95e916f493e037e to your computer and use it in GitHub Desktop.
Save seanbehan/80ac77006e8bf744d95e916f493e037e to your computer and use it in GitHub Desktop.
Create a multi site Flask application using Blueprints. This app will match hostname to serve a distinct application.
# set up /etc/hosts
# 127.0.0.1 site1.loc site2.loc
from flask import (
Flask
)
import site1, site2
app = Flask(__name__)
app.url_map.host_matching = True
app.register_blueprint(site1.app)
app.register_blueprint(site2.app)
if __name__ == '__main__':
app.run(debug=True, port=5000)
from functools import partial
from flask import (
Blueprint, jsonify
)
app = Blueprint('site1', __name__)
route = partial(app.route, host="site1.loc:5000")
@route("/")
def home():
return jsonify(
hello='site1'
)
from functools import partial
from flask import (
Blueprint, jsonify
)
app = Blueprint('site2', __name__)
route = partial(app.route, host="site2.loc:5000")
@route("/")
def home():
return jsonify(
hello='site2'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment