# example_blueprint.py
from flask import Blueprint
example_blueprint = Blueprint(
"example_blueprint", __name__, template_folder="templates"
)
@example_blueprint.route("/test")
def test():
return "<h1>Test</h1>"
# main.py
from flask import Flask
from .example_blueprint import example_blueprint
app = Flask(__name__)
app.register_blueprint(example_blueprint)
appp.run(debug=True)
# note: these two files have to be in the same folder
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound
simple_page = Blueprint('simple_page', __name__,
template_folder='templates')
@simple_page.route('/', defaults={'page': 'index'})
@simple_page.route('/<page>')
def show(page):
try:
return render_template(f'pages/{page}.html')
except TemplateNotFound:
abort(404)
from flask import Blueprint, jsonify
app_b_api = Blueprint("app_b", __name__)
@app_b_api.route("/b")
def home():
return "Hello, World!"
@app_b_api.route("/health_b.json")
def health():
return jsonify({"status": "UP"}), 200
from flask import Blueprint, jsonify
app_a_api = Blueprint("app_a", __name__)
@app_a_api.route("/a")
def home():
return "Hello, World!"
@app_a_api.route("/health_a.json")
def health():
return jsonify({"status": "UP"}), 200
from flask import Flask
from app_a import app_a_api
from app_b import app_b_api
app = Flask(__name__)
app.register_blueprint(app_a_api)
app.register_blueprint(app_b_api)
app.run(host="0.0.0.0", port = '8000', debug=True, threaded=True)