当前位置:网站首页>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.
边栏推荐
猜你喜欢
PyTorch显存机制分析
Redis - Data Types (Basic Instructions, String, List, Set, Hash, ZSet, BitMaps, HyperLogLog, GeoSpatial) / Publish and Subscribe
吃瓜教程task01 第1章 绪论
Flask framework learning: trailing slashes for routes
【Redis】Redis 的安装及图形化界面 Redis DeskTop Manager 的安装与使用
flaks框架学习:在 URL 中添加变量
Flask framework learning: template rendering and Get, Post requests
我的四核Cortex-A53学习之路
Flask框架学习:模板继承
一张图带你解读--如何从零开始学习接口自动化
随机推荐
搭建PX4开发环境
task05 PyTorch可视化
深入理解线程、进程、多线程、线程池
C语言版——通讯录进阶(文件版本)
Redis details
普林斯顿概率论读本读书笔记(阅读中......)
Flask框架学习:模板继承
flask框架学习:debug与配置项
LeetCode43.字符串相乘 (大数相乘可用此方法)
【win10+cuda7.5+cudnn6.0安装caffe①】安装cuda和cudnn
Django--20 implements Redis support, context, and interaction of context and interface
利用rand函数随机生成uuid
win下clion打包的.exe文件在无运行环境的电脑运行显示缺失各种.dll
Apache Commons OGNL语法说明_翻译
C语言——程序的编译与执行、宏定义详解
简单做份西红柿炒蛋778
QT QLabel控件(使用详解)
(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
ClionIDE通过指定编译器编译
(2) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Jmeter)