Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

flask blueprint

# 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
Comment

flask blueprints

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)
Comment

blueprint flask

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
Comment

blueprint flask

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
Comment

blueprint flask

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)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas sample frac 
Python :: python check for int 
Python :: how to convert ui file to py file 
Python :: tokens in python 
Python :: create a dictionary from dataframe 
Python :: how to launch a application using python 
Python :: python to pseudo code converter online 
Python :: rename a column 
Python :: string -1 python 
Python :: numpy shuffle along axis 
Python :: syntax error python 
Python :: range() in python 
Python :: download youtube video by python 
Python :: linux python virtual environment 
Python :: python interpreter 
Python :: how to use pyplot 
Python :: python while true 
Python :: how to extract digits from a string in python 
Python :: validate 
Python :: python max with custom function 
Python :: python hex 
Python :: how to check list is empty or not 
Python :: how to refresh page in flask 
Python :: rename data columns pandas 
Python :: precedence in python 
Python :: Pass a variable to dplyr "rename" to change columnname 
Python :: how to make an argument optional in python 
Python :: list append python 3 
Python :: python pattern 
Python :: python __name__ == "__main__" 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =