问题
一定要把项目路径导入到系统路径中
结构目录
api_blueprint.py
from flask import Flask
import sys
import pathlib
# 把当前目录加入系统路径
base_dir = pathlib.Path(sys.argv[0]).parent.parent
if sys.path.count(base_dir) == 0 :
sys.path.append(str(base_dir))
#查看系统路径
# print(sys.path)
# 导入api
from apis.dateil import detail
from apis.indexs import index
app = Flask(__name__)
# 使用蓝图访问api
app.register_blueprint(detail)
app.register_blueprint(index)
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000)
index.py
# 导入蓝图
from flask import Blueprint,request
# 使用蓝图
index = Blueprint('index',__name__)
@index.route('/',methods=['GET'])
def index_view():
return '首页'
detail .py
from flask import Blueprint,request
detail = Blueprint('detail',__name__)
@detail.route('/detei',methods=['GET','POST'])
def detail_view():
data = request.form.get('123')
return data