Configure Flask dev server to be visible across the network

前端 未结 14 2415
面向向阳花
面向向阳花 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:52

    If you're having troubles accessing your Flask server, deployed using PyCharm, take the following into account:

    PyCharm doesn't run your main .py file directly, so any code in if __name__ == '__main__': won't be executed, and any changes (like app.run(host='0.0.0.0', port=5000)) won't take effect.

    Instead, you should configure the Flask server using Run Configurations, in particular, placing --host 0.0.0.0 --port 5000 into Additional options field.

    More about configuring Flask server in PyCharm

提交回复
热议问题