Configure Flask dev server to be visible across the network

前端 未结 14 2444
面向向阳花
面向向阳花 2020-11-21 05:57

I\'m not sure if this is Flask specific, but when I run an app in dev mode (http://localhost:5000), I cannot access it from other machines on the network (with

14条回答
  •  野性不改
    2020-11-21 06:44

    Try this if the 0.0.0.0 method doesn't work

    Boring Stuff

    I personally battled a lot to get my app accessible to other devices(laptops and mobile phones) through a local-server. I tried the 0.0.0.0 method, but no luck. Then I tried changing the port, but it just didn't work. So, after trying a bunch of different combinations, I arrived to this one, and it solved my problem of deploying my app on a local server.

    Steps

    1. Get the local IPv4 address of your computer. This can be done by typing ipconfig on Windows and ifconfig on Linux and Mac.

    Please note: The above step is to be performed on the machine you are serving the app on, and on not the machine on which you are accessing it. Also note, that the IPv4 address might change if you disconnect and reconnect to the network.

    1. Now, simply run the flask app with the acquired IPv4 address.

      flask run -h 192.168.X.X

      E.g. In my case (see the image), I ran it as:

      flask run -h 192.168.1.100

    On my mobile device

    Optional Stuff

    If you are performing this procedure on Windows and using Power Shell as the CLI, and you still aren't able to access the website, try a CTRL + C command in the shell that's running the app. Power Shell gets frozen up sometimes and it needs a pinch to revive. Doing this might even terminate the server, but it sometimes does the trick.

    That's it. Give a thumbs up if you found this helpful.

提交回复
热议问题