我正在尝试在Google Colab上实现Flask服务器 我遵循了此stack overflow链接中的步骤。
它不是开发服务器,我使用了参数host ='0.0.0.0'
ng serve --configuration es5
输出-
import socket
print(socket.gethostbyname(socket.getfqdn(socket.gethostname())))
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return("Hello World!")
import threading
threading.Thread(target=app.run, kwargs={'host':'0.0.0.0','port':'80'}).start()
然后,从请求模型中获取结果,例如
172.28.0.2
* 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
输出-
import requests
r = requests.get("http://172.28.0.2/")
print(r.status_code)
print(r.encoding)
print(r.apparent_encoding)
print(r.text)
它执行得很好,但是当我打开链接时,它在端口80上生成了(172.28.0.2),浏览器显示“无法访问此站点”
如何在浏览器中查看flask的实现
谢谢