当前位置:网站首页>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 = True
to enable:
app.run(debug=True)
- Set the configuration item and open it in the form of configuration parameter:
app = Flask(__name__)app.config['DEBUG'] = True
Open 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
config
property 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'] = True
Or 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.py
file 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.
边栏推荐
猜你喜欢
selenuim使用cookie登录京东
(三)性能实时监控平台搭建(Grafana+Prometheus+Node_explorer+Jmeter)
The most complete installation tutorial of Pytorch (one step)
阿里云无法远程连接数据库MySQL错误码10060解决办法_转载
task05 PyTorch可视化
更新啦~人生重开模拟器自制
【转载】CMake 语法 - 详解 CMakeLists.txt
(二)性能实时监控平台搭建(Grafana+Prometheus+Jmeter)
Pytorch最全安装教程(一步到位)
【网站小白】Hibernate插入数据成功,不报错,但是数据库中没有值
随机推荐
task04 Pytorch进阶训练技巧
QT Mat转HObject和HObject转Mat 图像视觉处理
QT circle函数(图片标注)
【C语言进阶】第一篇深度剖析整数数据在内存中的存储(一)
第8章 函数探幽 -1
curl 命令调用接口demo
task05 PyTorch可视化
RK3399上的Tengine实践笔记
输入字符串,替换其中敏感词进行输出
(三)性能实时监控平台搭建(Grafana+Prometheus+Node_explorer+Jmeter)
C语言——程序的编译与执行、宏定义详解
task06 PyTorch生态
总结:交叉验证
Decryption of BitLocker
pytorch基础之 pytorch 模型开发模板
Oracle常用语句归纳_持续更新
C语言文件操作——数据文件类型、文件判断、文件缓冲区详解
IDEA模板总结
(1) Docker installs Redis in practice (one master, two slaves, three sentinels)
(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)