flask中 app.config['XXX'] 读取

2018-10-14  本文已影响0人  违规昵称不予展示

0x01 正确情况

配置文件为:
文件名为:config.py

DEBUG = True

读取语句为:

app.config.from_object('config')
print(app.config['DEBUG'])

输出为:

True

0x02 DEBUG 是flask的默认参数

配置文件为:
文件名为:config.py

Debug = True

读取语句为:

app.config.from_object('config')
print(app.config['DEBUG'])

输出为:

False

0x03 app.config['xx'] 会忽略小写的xx

配置文件为:
文件名:config.py

Debug = True

读取语句为:

app.config.from_object('config')
print(app.config['Debug'])

输出为:

(fisher-sBQPORRV) F:\fisher>python fisher.py
Traceback (most recent call last):
  File "fisher.py", line 9, in <module>
    print(app.config['Debug'])
KeyError: 'Debug'
上一篇 下一篇

猜你喜欢

热点阅读