Configure Flask dev server to be visible across the network

前端 未结 14 2443
面向向阳花
面向向阳花 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 07:03

    You can also set the host (to expose it on a network facing IP address) and port via environment variables.

    $ export FLASK_APP=app.py
    $ export FLASK_ENV=development
    $ export FLASK_RUN_PORT=8000
    $ export FLASK_RUN_HOST=0.0.0.0
    
    $ flask run
     * Serving Flask app "app.py" (lazy loading)
     * Environment: development
     * Debug mode: on
     * Running on https://0.0.0.0:8000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: 329-665-000
    

    See How to get all available Command Options to set environment variables?

提交回复
热议问题