Unable to connect to Flask local server

白昼怎懂夜的黑 提交于 2021-02-05 11:43:43

问题


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

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)

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.

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?


回答1:


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

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

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")


来源:https://stackoverflow.com/questions/63855176/unable-to-connect-to-flask-local-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!