官术网_书友最值得收藏!

Blueprint

Flask introduces the concept of blueprint for developing application components and command patterns in an application or across multiple applications. It helps to comprehend large-scale applications by centralizing the root Flask application object. Blueprint acts as a separate Flask application without creating an actual Flask application object, and is able to instantiate application objects, initialize several extensions, and register a collection. It also provides template filters, static files, templates, and other utilities.

As explained in the auth module, we will also create the Blueprint instance for the Todo application. This will be configured in the app.__init__.py file, which is where we created the Flask application instance.

The following is a code snippet of the todo module's blueprint.

File—todo/__init__.py:

from flask import Blueprint

todo = Blueprint('todo', __name__)

from . import views

Once we have created the blueprint object of the todo module, we can use it to add routes in views and register the blueprint with the Flask application instance.

The following is the code snippet of app/__init__.py, which is where we are going to register blueprint:

from .auth import auth as auth_blueprint
from app.config import config

app = Flask(__name__)
app.config.from_object(config[environment])

app.register_blueprint(todo_blueprint, url_prefix='/todos')
主站蜘蛛池模板: 荔波县| 厦门市| 铁岭县| 商丘市| 忻城县| 汝城县| 黄冈市| 金溪县| 马关县| 绥江县| 陆河县| 安陆市| 长海县| 扎囊县| 嘉义县| 舞阳县| 科技| 九龙县| 崇阳县| 信丰县| 云龙县| 江都市| 新营市| 荥经县| 望奎县| 伊春市| 南陵县| 南平市| 扶绥县| 张家界市| 银川市| 阿克苏市| 阿荣旗| 阿坝| 阳曲县| 南昌县| 平湖市| 交口县| 故城县| 蚌埠市| 屯留县|