Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何正确连接到自己的flask服务器?_Python_Html_Flask_Web - Fatal编程技术网

Python 如何正确连接到自己的flask服务器?

Python 如何正确连接到自己的flask服务器?,python,html,flask,web,Python,Html,Flask,Web,我目前拥有的代码如下所示: from flask import Flask app = Flask(__name__) @app.route("/") def main(): return "welcome to my page" app.run(debug=True, host="0.0.0.0", port=8080) 当我尝试在Pychar上运行代码时,我得到以下结果: "C:\Users\radbo\

我目前拥有的代码如下所示:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def main():
    return "welcome to my page"


app.run(debug=True, host="0.0.0.0", port=8080)
当我尝试在Pychar上运行代码时,我得到以下结果:

"C:\Users\radbo\AppData\Local\Programs\Python\Python39\python.exe C:/Users/radbo/yay.py
 * Serving Flask app "yay" (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
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 161-701-749
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

"
而是返回:

Hmmm… can't reach this page It looks like the webpage at http://0.0.0.0:8080/ might be having issues, or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID
我的问题如下: 我的服务器是可连接的还是不存在?

在Flask(和其他服务器技术)
0.0.0
是一种约定,表示“绑定所有地址”。但是,
0.0.0.0
不是浏览器到达目的地的有效地址

这意味着您的flask服务器将绑定到它的环回地址
127.0.0.1
(别名
localhost
几乎总是指向该地址)

因此,在浏览器中,您应该使用或http://localhost:8000

如果您的计算机有其他与之关联的IP地址,您也可以通过这些IP地址访问它,前提是防火墙规则允许通信

请注意,使用
0.0.0.0
意味着您的Web服务器也将响应来自网络上其他客户端的请求,特别是在使用
debug=True
时,如果暴露,可能会带来安全风险,这显然是不可取的。如果你只打算在自己的计算机上使用WebApp,考虑使用<代码>主机= 127.0.0.1