使用蓝图时找不到烧瓶URL

dem*_*rit 1 python blueprint flask

这确实很奇怪,但是正面临这个问题。一切正常,我几乎用完了该应用程序,但突然停了下来。我隔离了代码,我意识到当我注册一个蓝图并在路由上使用它时,它无法返回说没有找到URL。这是隔离的代码:

from flask import Flask, render_template, Blueprint

app = Flask(__name__)

home = Blueprint('home', __name__, static_folder='static', template_folder='template')
app.register_blueprint(home)


@home.route('/')  #<---This one does not work
# @app.route('/') <--- This one works
def index():
    return "This is the index route."
    # return render_template('layer.html')


if __name__ == '__main__':
    app.run()
Run Code Online (Sandbox Code Playgroud)

sta*_*mer 5

移动app.register_blueprint(home)定义的后路线。

from flask import Flask, Blueprint

app = Flask(__name__)

home = Blueprint('home', __name__, static_folder='static', template_folder='template')

@home.route('/')  
def index():
    return "This is the index route."

app.register_blueprint(home)

if __name__ == '__main__':
    app.run()
Run Code Online (Sandbox Code Playgroud)