Python 错误地址无效,找不到404,本地主机:8000

Python 错误地址无效,找不到404,本地主机:8000,python,flask,localhost,Python,Flask,Localhost,我真的不知道从哪里开始,也不知道这个问题从哪里来,这就是为什么我找不到这个问题的确切标题。这是我的问题 我从github复制了这段代码,作为了解API的教程的一部分: from flask import Flask app = Flask(__name__) @app.route('/readHello') def getRequestHello(): return "Hi, I got your GET Request!" @app.route('/createHello', m

我真的不知道从哪里开始,也不知道这个问题从哪里来,这就是为什么我找不到这个问题的确切标题。这是我的问题

我从github复制了这段代码,作为了解API的教程的一部分:

from flask import Flask
app = Flask(__name__)


@app.route('/readHello')
def getRequestHello():
    return "Hi, I got your GET Request!"

@app.route('/createHello', methods = ['POST'])
def postRequestHello():
    return "I see you sent a POST message :-)"


@app.route('/updateHello', methods = ['PUT'])
def updateRequestHello():
    return "Sending Hello on an PUT request!"


@app.route('/deleteHello', methods = ['DELETE'])
def deleteRequestHello():
    return "Deleting your hard drive.....haha just kidding! I received a DELETE request!"

if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=8000)
我用vagrant安装了一个虚拟机,它运行得很好。当我尝试在机器上运行此代码时(我在本地机器上尝试过,并且出现了相同的问题),终端会返回以下信息:

vagrant@vagrant:/vagrant$ python api_server.py
 * Serving Flask app "api_server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 203-304-000
因此,我尝试访问上的页面,但出现错误“ERR\u ADDRESS\u INVALID”。当我尝试使用(不确定区别是什么,但我发现它对某些人有效)时,我得到了另一个错误,这次404页面未找到

谢谢您的帮助。

您没有添加“/”路由侦听

@app.route('/')
def getMainRequest():
    return "Hi, Server is running fine!"

嗨,谢谢你的回答!它在地址127.0.0.1:8000下工作,但仅在表面上,因为它返回了一句“嗨,服务器运行正常,但是,当我尝试发送除get之外的api请求时,我会像以前一样出现错误,我认为您没有正确访问api使用curl进行检查,它将给出正确的响应``curl-X get curl-X POST curl-X PUT curl-X DELETE``这篇文章将帮助您理解这个问题