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