1_Flask open debug

DEBUG mode

Why turn debug mode:

  1. If you turn on the debug mode, then the code if an exception is thrown, you can see the specific error messages, as well as the specific location of the error code in the browser page, enabling developers to easily debug.
  2. If you turn on the debug mode, after modifying Pythonthe code and saved, the flask will automatically reboot, load the latest code, reload the entire web site without the need to re-run.

Configuration 4 ways debug mode:

  1. In app.run()passing a parameterdebug=True

    ...
    if __name__ == '__main__':
        app.run(debug=True)
  2. To apptarget debug attribute set to True

    ...
    app = Flask(__name__)
    app.debug = True
    ...
  3. Configuration parameters form: app.config.update(DEBUG=True)# DEBUG attention at this time is to be capitalized

    app = Flask(__name__)
    app.config.update(DEBUG=True)
  4. Load Profiles (config.py) to achieve: app.config.from_object(config)

    # 1. 新建 config.py 文件,用来存储有关配置的信息
    DEBUG = True
    
    --------------------------------------------------
# 2. 在运行的flask 文件中, 导入 配置文件config.py
from flask import Flask
import config

app = Flask(__name__)
app.config.from_object(config)
...
​```

Guess you like

Origin www.cnblogs.com/nichengshishaonian/p/11609998.html