7.读取配置参数的方式(flask学习笔记)

读取配置参数

1、直接从全局对象的app的config字典中取值

print(app.config.get("ITCAST"))

2、通过current_app获取参数
前提需要:

import current_app
print(current_app.config.get("ITCAST"))

演示:

#定义视图函数,装饰器去做
@app.route("/")
def index():
    """定义视图函数
    反应体字符串直接写
    """
    # a = 1  /  0
    #读取配置参数
    #1、直接从全局对象的app的config字典中取值
    # print(app.config.get("ITCAST"))
    #2、通过current_app获取参数
    print(current_app.config.get("ITCAST"))
    return  "hello flask"
发布了60 篇原创文章 · 获赞 8 · 访问量 3338

猜你喜欢

转载自blog.csdn.net/qq_43476433/article/details/103425822