Last active
November 20, 2022 17:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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