【问题标题】:Flask Hello World Program Not working 404 Not Found ErrorFlask Hello World 程序不工作 404 Not Found 错误
【发布时间】: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:5000http://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/…

标签: python flask


【解决方案1】:

是的,您可以通过以下方式消除错误 404 not found: 1:您应该编写命令 netstat -a -b 来检查哪个端口没有空闲或忙于做某事或 2:写在你的代码 app.run(port=4996) 而不是 app.run() 默认选择端口号。 50000。

【讨论】:

    猜你喜欢
    • 2012-09-09
    • 2020-01-06
    • 2017-11-25
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多