Configure Flask dev server to be visible across the network

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

    Go to your project path on CMD(command Prompt) and execute the following command:-

    set FLASK_APP=ABC.py

    SET FLASK_ENV=development

    flask run -h [yourIP] -p 8080

    you will get following o/p on CMD:-

    • Serving Flask app "expirement.py" (lazy loading)
      • Environment: development
      • Debug mode: on
      • Restarting with stat
      • Debugger is active!
      • Debugger PIN: 199-519-700
      • Running on http://[yourIP]:8080/ (Press CTRL+C to quit)

    Now you can access your flask app on another machine using http://[yourIP]:8080/ url

    0 讨论(0)
  • 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?

    0 讨论(0)
提交回复
热议问题