Flask cannot modify access ip and port

flask project cannot modify access ip and port

Windows uses the flask framework to write the simplest case according to the tutorial, the code is as follows. But when I wanted to modify the access to ip, I found that it would not work. According to the tutorial, changing host to (0.0.0.0) is accessible to the public network. But I found that no, still not after turning off the firewall. It is still not possible to change host to local fixed ip. Not even if you want to simply modify the port. Check that port 8082 is unoccupied and rule out the possibility that the port is occupied.

related codes

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "Index Page1111"

@app.route("/hello")
def hello():
    return "Hello Wo111rld"


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0" ,port=8082)


each startup project can be started normally, and access to the default: http://127.0.0.1:5000/ is also available. No matter what ip I change to, I can open http://127.0.0.1:5000/ normally. Helpless

Connected to pydev debugger (build 181.5087.37)
 * Serving Flask app "app.py" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Restarting with stat
pydev debugger: process 271868 is connecting

 * Debugger is active!
 * Debugger PIN: 235-356-364
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Apr.05,2021

although you have found the problem yourself, I would like to say that do not use Pycharm to start flask projects.
I encountered this similar problem because when I used flask-socketio to write websocket applications, I found that pycharm could not start the project normally
. So if you are writing applications with flask, it is best to use terminal startup projects


this is a problem with PyCharm configuration. As Atey encountered, all you need to do is delete the configuration file of type Flask identified and created by PyCharm and change it to a configuration file of type Python.
the entry for modifying the configuration file is generally located in the upper right corner of the window. In the drop-down window, click Edit Configurations, to enter editing.
give it a try.


visit 192.168.0.101 VOL5000

under your own ping.

I'm running locally now

192.168.0.102-- [08/Aug/2018 11:25:01] "GET / HTTP/1.1" 200-
192.168.0.102-[08/Aug/2018 11:25:01] "GET / favicon.ico HTTP/1.1" 404-


correct understanding is that the core is to change the host to (0.0.0.0), which can be accessed by the public network. But I found that no . If by extranet you mean other machines on the Internet, you may need to know about ISP and intranet penetration .

but what @ f2st says can be tested locally, in fact, there is no problem with the external network. The machine you use to access the server and your server need to be in the same local area network .


1, answer for the first time

< hr >

restart the machine to make sure you have shut down the original flask process.

2. Answer for the second time after the subject posted the startup information

< hr >

from the startup information, Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

)

you must use http://127.0.0.1:5000/ to access the page.

I ask weakly, subject, are you sure your script name is app.py?


maybe my question misled you. It should be a project configuration issue, not a code issue. There is nothing wrong with the above code.
although I have solved this problem, I have used a very stupid approach. @ Li Yi helped me remotely and decided that the problem was that the local app file was not executed. I searched a lot of places and found that the running environment needed to be configured. However, I didn't find out how to configure it.
so create a new folder, create a flask project without using pychram, and manually create a virtual environment.
1, pip install virtualenv
2, python-m virtualenv env
then create the flask project with pychram, and configure configuration, as follows

can run the local app.py
Thank @ Li Yi for his help and look forward to the answers from other great gods.
Resources:
https://blog.csdn.net/qq_3348.

Menu