Python Flask:蓝图路由规划
来自CloudWiki
创建蓝图
from flask import Blueprint route_imooc = Blueprint( "imooc_page",__name__) @route_imooc.route("/") def index(): return "imoos index page" @route_imooc.route( "/hello") def hello(): return "imooc hello"
注册蓝图
from flask import Flask from imooc import route_imooc app = Flask(__name__) app.register_blueprint(route_imooc,url_prefix = "/imooc" ) @app.route("/") def hello_world(): return "Hello World" @app.route("/api") def index(): return 'Index pagel' @app.route("/api/hello") def hello(): return 'Hello World' if __name__ == '__main__':#程序入口 app.run(host='0.0.0.0')