Flask表示其正在运行,但代码未在浏览器中显示

时间:2019-04-13 07:36:10

标签: flask windows-10

我正在尝试在Windows 10计算机上运行Flask代码。命令行显示正在提供Flask应用程序。

(HelloWorld) C:\Users\binoy\dev\HelloWorld>python HelloWorld.py
 * Serving Flask app "HelloWorld" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 211-440-231
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [13/Apr/2019 11:27:18] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [13/Apr/2019 11:27:18] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [13/Apr/2019 11:28:09] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [13/Apr/2019 11:28:17] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [13/Apr/2019 11:30:17] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [13/Apr/2019 11:34:05] "GET /favicon.ico HTTP/1.1" 404 -

但是当我打开浏览器时,收到消息404 Not Found

知道为什么我看不到应用程序

1 个答案:

答案 0 :(得分:0)

谢谢。我不得不更改代码。

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"
if __name__ == '__main__':
    app.run(host='0.0.0.0', threaded=True, debug=True)

我插入了

`if _name_=='_main_':` 

之前

 `@app.route("/") before `@app.route("/")`

现在它正在运行!