简体   繁体   中英

Unable to connect to Flask local server

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM