【发布时间】:2018-06-13 17:28:43
【问题描述】:
我正在尝试开始使用 Flask,但遇到 hello world 程序的 404 Not Found 错误。
我使用的程序:
from flask import Flask
app = Flask(__name__)
@app.route('/')
@app.route('/index.html')
def hello_world():
return 'Hello, World'
if __name__== '__main__':
app.run(host='localhost')
然后我运行
$export FLASK_APP = minimal.py
$flask run
返回:
* Serving Flask app "minimal"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger PIN 127-804-808
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
当我访问http://localhost:5000 或http://127.0.0.1:5000 时,我得到:
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
我的主机文件如下所示:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
知道有什么问题吗?谢谢
【问题讨论】:
-
您的代码对我有用。我唯一的想法是
FLASK_APP是错误的 -
你做了什么来运行代码?
-
使用以下命令解决了这个问题:app.run(debug=True, port=4996),我认为默认端口 5000 有问题。
-
我在哪里找到了解决方案:stackoverflow.com/questions/35818713/…