无法连接到Flask本地服务器 [英] Unable to connect to Flask local server

查看:48
本文介绍了无法连接到Flask本地服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python和Flask构建一个Web应用程序.我开始在Ubuntu上进行开发,到目前为止,它可以正常工作.

I'm trying to build an web app with python and Flask. I started working on it on Ubuntu and it works so far.

但是,将项目拉入安装了相同先决条件的Windows环境中是行不通的.更详细地说,运行输出看起来还不错

However, pulling the project into an windows environment with the same prerequisites installed does not work. More detailed, the run output looks quite alright

 * 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: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 239-929-141
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

但是当访问0.0.0.0:8080时,浏览器无法访问它.而且没有更多的输出与正在发生的事情有关.

But when accessing 0.0.0.0:8080 the browser is unable to reach it. And there's no more output related to what's happening.

我也使用基本的hello world flask应用程序进行了测试,结果是相同的(在Windows上).知道操作系统是否是这里的问题吗?还是什么呢?

I tested this also with the basic hello world flask app and the result is the same (on windows). Any idea if the OS is the problem here? or what else could it be?

推荐答案

http://0.0.0.0 通常不会无效,您可能需要在浏览器中切换到http://localhost:8080.

http://0.0.0.0 often doesn't work, you will likely need to switch to http://localhost:8080 in your browser.

还要确认您已将烧瓶设置为使用0.0.0.0,而不是127.0.0.1.

Also validate you have set flask to use 0.0.0.0 and not 127.0.0.1.

我想我应该解释第二部分,在 routes.py 文件中,您要确保将主机设置为0.0.0.0,否则将无法访问它.因此,在您的 routes.py 底部,请确保您拥有:

I figured I should explain the second part, within a routes.py file you want to make sure you set the host to 0.0.0.0 otherwise you won't be able to access it. So at the bottom of your routes.py make sure you have:

from flask import Flask
app = Flask(__name__)
app.run(host="0.0.0.0")

这篇关于无法连接到Flask本地服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆