当前位置:网站首页>Flask framework to study: the debug and configuration items
Flask framework to study: the debug and configuration items
2022-08-11 05:45:00 【weixin_42576837】
Enable debug mode
- Pass parameters in
app.run(), usedebug = Trueto enable:
app.run(debug=True)- Set the configuration item and open it in the form of configuration parameter:
app = Flask(__name__)app.config['DEBUG'] = TrueOpen in Edit Configurations set in 3.pycharm:

Note: You can only see FLASK_DEBUG if the new Flask project is created here. If it is a new python project, this option is not available.
There are several pits here: Here my file name is: debug mode.py
But if you have not executed this file, this location will not display the current file:
My understanding is that you have to do it once, and then you will be in Edit Configurations generates a configuration item information of the current file, and then you edit the configuration information and set FLASK_DEBUG to select.
Then, when executing, you cannot directly right-click to execute
There is already a configuration item of debug mode.py in the above configuration information, you have already set it up, if you right-click to run now, note: it writes debug mode.py(1), this will generate another configuration item of debug mode.py(1), I don't understand why there is one more (1) comes out, but if you right-click to run, the debug mode is still not set.
The correct way to run is to click the run button next to it after Edit Configurations is set.
That's fine.
But the problem is that every time you create a new py file, you need to set this up once, which is still very troublesome.
Configuration item settings
- Use the
configproperty of the Flask object to manipulate the value of the configuration.
config is essentially a subclass of a dictionary, which can be manipulated like a dictionary:
For example, the debug mode above isIt can be set in this form:
app = Flask(__name__)app.config['DEBUG'] = TrueOr to update multiple configuration values at once you can use the dict.update() method:
app.config.update(TESTING=True,SECRET_KEY=b'_5#y2L"F4Q8z\n\xec]/')- When there are too many configuration items, you can create a configuration file and import these configuration information.
We create aconfig.pyfile and write the corresponding key-value pair in it
then import in our main file, firstimport config
then useapp.config.from_object(config)will do.
In addition, app.config.from_pyfile() function, this method does not need to import config
directly app.config.from_pyfile('config.py') can be.
But I still haven't turned on the debug mode here, and JSON_AS_ASCII = False does take effect. I don't know why.
边栏推荐
猜你喜欢
随机推荐
win下clion打包的.exe文件在无运行环境的电脑运行显示缺失各种.dll
Who am I ?
基于TF-IDF 文本相似性实战 详细教程
pytorch矩阵运算问题
吃瓜教程task01 第1章 绪论
flaks framework learning: adding variables to the URL
第13章 类的继承-1
(1) Docker installs Redis in practice (one master, two slaves, three sentinels)
一张图带你解读--如何从零开始学习接口自动化
将double类型的数据转为字符串
输入字符串,替换其中敏感词进行输出
【分享】一个免费语料库
The most complete installation tutorial of Pytorch (one step)
postman脚本的应用
Keras与tensorflow 使用基础
【翻译】博客游戏项目Q1K3 – 制作
vftpd本地可以连接,远程连接超时的解决
Win下安装不同版本的MinGW(g++/gcc)以及对应clion编辑器的配置
Redis - the solution to the failure of connecting to the redis server in linux using jedis
LeetCode刷题Top100之两数之和









