How to debug a Flask app

前端 未结 13 2484
陌清茗
陌清茗 2020-11-22 03:08

How are you meant to debug errors in Flask? Print to the console? Flash messages to the page? Or is there a more powerful option available to figure out what\'s happening

13条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 03:45

    with virtual env activate

    export FLASK_DEBUG=true
    

    you can configure

    export FLASK_APP=app.py  # run.py
    export FLASK_ENV = "development"
    

    to start

    flask run
    

    the result

     * Environment: development
     * Debug mode: on
     * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: xxx-xxx-xxx
    

    and if you change

    export FLASK_DEBUG=false
    
     * Environment: development
     * Debug mode: off
     * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    

提交回复
热议问题