flask 蓝图

1、目录结构

 2、app/__init__.py

from flask import Flask

from app.api import api
from app.web import web

'''
定义APP,注册蓝图
'''
def create_app():

    app=Flask(__name__)
    app.config.from_object('config')
    app.register_blueprint(web)
    app.register_blueprint(api)
    return app

3、web/__init__.py

from flask import Blueprint

#定义蓝图 web
=Blueprint('web',__name__)
#这里需要导入使用web蓝图的模块
from app.web import book from app.web import hello

4、web/hello.py

from app.web import web

#使用web蓝图
@web.route('/hello/')
def hello():

    return "hello juxiaona"

5、config.py

DEBUG=True

6、程序运行入口

from app import create_app

app=create_app()


if __name__=="__main__":

    app.run(host='0.0.0.0',debug=app.config['DEBUG'])

猜你喜欢

转载自www.cnblogs.com/tangqiu/p/12564853.html