flask框架-蓝图

版权声明:青春看似荒唐,没人会选择投降。 https://blog.csdn.net/sdzhr/article/details/81700669
from flask import Flask, Blueprint

app = Flask(__name__)
#创建蓝图对象参数1蓝图名,参数2模块名,参数3静态资源文件夹,参数四模板资源文件夹,参数5url路由前缀
blue_print = Blueprint('bule', __name__, static_folder='static', template_folder='templates', url_prefix='/blue')


#添加蓝图路由
@blue_print.route('/index')
def blue_index():
    return "this is blue_index"


@blue_print.route('/')
def bule_root():
    return "this is blue_root"


#将蓝图注册到app中
app.register_blueprint(blue_print)


@app.route('/index')
def index():
    return "HelloWorld"


if __name__ == "__main__":
    print(app.url_map)
    app.run(debug=True)

猜你喜欢

转载自blog.csdn.net/sdzhr/article/details/81700669