flask - NameError: name 'app' is not defined

前端 未结 2 2027
花落未央
花落未央 2020-12-31 12:15

I\'m running Flask through thescript, below (run.py)

#!flask/bin/python
from app import app
app.run(debug=True)

When runni

2条回答
  •  爱一瞬间的悲伤
    2020-12-31 12:42

    This error is because of you are not defining app and directly using app

    Solution is add this line in your code : app Flask(__name__)

    Example: app.py

    from flask import Flask
    #You need to use following line [app Flask(__name__]
    app = Flask(__name__)
    @app.route('/')
    def index():
        return "Hello World with flask"
    if __name__ == '__main__':
        app.run(port=5000,debug=True)
    

提交回复
热议问题