这是我的回购https://github.com/poc7667/flask_blueprint
我想将所有路由分成子模块,
我将在根文件夹
中运行python web.py
我希望我可以通过/hihi
sub_1
模块下的路由http://localhost:8888/hihi
但是我得到了Not found error
from flask import Flask, Response, request, url_for
app = Flask(__name__)
from sub_1 import sub_1_mod
app.register_blueprint(sub_1_mod, url_prefix="/")
if __name__ == "__main__":
app.run(debug=True, host='localhost', port=8888)
# -*- coding: utf8 -*-
from sub_1 import sub_1_mod
from flask import Flask, Response, request
app = Flask(__name__)
@app.route("/hihi", methods=['GET'])
def hihi():
return make_response(["hihi"], VERSION)
from flask import Blueprint
sub_1_mod = Blueprint('sub_1', __name__)
import sub_1.web
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
答案 0 :(得分:1)
在 sub_1 / web.py 中,请勿创建其他Flask
应用程序。而是将路线添加到现有的blueprint
from sub_1 import sub_1_mod
@sub_1_mode.route("/hihi", methods=['GET'])
def hihi():
return make_response(["hihi"], VERSION)