register_blueprint doesn't add route to Flask app

前端 未结 1 471
甜味超标
甜味超标 2021-01-14 03:51

I created a blueprint with a route and registered the blueprint with my Flask app. However, I get a 404 when requesting the route. What is wrong with my code?



        
相关标签:
1条回答
  • 2021-01-14 04:31

    You registered the blueprint before the code that registered the route executed. Move register_blueprint after the blueprint has been fully defined.

    bp = Blueprint('test', __name__, url_prefix='/test')
    
    @bp.route('/')
    def home():
        return 'Hello, World!'
    
    app.register_blueprint(bp)
    
    0 讨论(0)
提交回复
热议问题