我正在尝试使用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
任何想法都错了吗?谢谢
答案 0 :(得分:0)
是的,你可以删除以下方式找不到的错误404: 1:你应该写命令netstat -a -b来检查哪个端口没有空闲或忙于做某事或 2:在您的代码中写入app.run(port = 4996)而不是app.run(),默认选择端口号。 50000