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 :: panda loc conditional 
Python :: pygame get surface region 
Python :: Python NumPy stack Function Example with 1d array 
Python :: create folders in python overwright existing 
Python :: theme_use() tkinter theme usage 
Python :: python download images from unsplash 
Python :: management command in django 
Python :: looping through the list 
Python :: accumulator programming python 
Python :: node 14 alpine add python 
Python :: quadratic equation python 
Python :: get coordinates of an image from a pdf python 
Python :: logging python 
Python :: encapsulation in python 
Python :: Python program to read a random line from a file 
Python :: pandas split cell into multiple columns 
Python :: python not equal to 
Python :: migrations.RunPython 
Python :: python get element by index 
Python :: Python RegEx SubString – re.sub() 
Python :: python - match two df on a variable with different name 
Python :: How to take n space separated Integer in a list in python? 
Python :: python trim zero off end of list 
Python :: extract decimal number from string python 
Python :: python melt 
Python :: DIF_GCD 
Python :: are tuples in python mutable 
Python :: python code for create diamond shape with integer 
Python :: flask add_url_rule 
Python :: re.search variable 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =