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 :: stop function python 
Python :: pandas groupby values in list 
Python :: taking array input in python 
Python :: multiprocessing join python 
Python :: add a button on tkinter 
Python :: python random array 
Python :: sns how to change color if negative or positive 
Python :: python run powershell command and get output 
Python :: count nan values 
Python :: matplotlib figure size not working 
Python :: spotify api python 
Python :: python timeit 
Python :: add new row to dataframe pandas 
Python :: splitting column values in pandas 
Python :: messagebox python pyqt 
Python :: python reading csv files from web 
Python :: merge multiple excel files with multiple worksheets into a single dataframe 
Python :: python seaborn color map 
Python :: Iterate through string backwards in python 
Python :: only read some columns from csv 
Python :: how to calculate the variance of all columns in python 
Python :: write pyspark dataframe to csv 
Python :: selenium webdriver options python 
Python :: remove part of string python 
Python :: how to download packages using pip 
Python :: python tkinter label widget 
Python :: aws django migrate 
Python :: openpyxl read sheet row by row 
Python :: how to make text to speech in python 
Python :: fastapi upload file save 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =