问题描述
我是烧瓶的新来者.我无法访问localhost:5000或127.0.0.1:5000.我正在用烧瓶.我尝试了许多解决方案,但没有一个对我有用.这是代码
I am a newcomer to flask. I cannot access localhost:5000 or 127.0.0.1:5000 . I am using flask . I have tried many solutions but none of them worked for me.Here's the code
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return ('Hello World')
if __name__ == '__main__':
app.run()
我明白了
* Serving Flask app "__main__" (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: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
当我进入localhost:5000或127.0.0.1:5000时,我会得到
when i go to localhost:5000 or 127.0.0.1:5000 , i get
推荐答案
尝试像这样运行您的应用程序:
Try to run your app like this:
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000)
这也使服务器在外部可见.如果计算机的IP地址是 192.168.X.X
,则可以从同一网络通过5000端口访问它.
This also makes the server externally visible. If the IP address of the machine is 192.168.X.X
then, from the same network you can access it in 5000 port.
防火墙也可能是一个问题,在这种情况下,请执行以下操作:
It could also be an issue with the firewall, in which case, do the following:
sudo ufw allow 5000
由于您正在Google Colab上运行,而不是在本地系统上运行.运行步骤会有所不同.
Since you are running on Google Colab and not on your local system. The running steps would vary.
请注意
按照步骤此处使其与 flask-ngrok
这篇关于使用Google Colab上的Python Flask连接到本地主机吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!