# coding:utf-8

from flask import Flask, current_app

# import demo
# 创建flask的应用对象
# __name__ 标识当前对象的模块名字
#          模块名:flask以这个模块所在的目录为总目录,默认这个目录中的static为静态目录,
#           templates :模板目录

app = Flask(__name__,
            static_url_path='/python',  # 静态资源的url前缀
            static_folder='static',  # 静态文件的目录,默认就是static
            template_folder='templates'  # 模板文件目录,默认就是templaters
            )


# 配置参数的使用方式
# 1.使用配置文件
# app.config.from_pyfile('config.cfg')

# 2. 使用对象配置参数   项目中使用
class Config(object):
    DEBUG = True
    ITCAST = 'python'


app.config.from_object(Config)


# 3.直接操作config的字典对象   参数少时 使用
# app.config['DEBUG'] = True


@app.route('/')
def index():
    """定义的视图函数"""
    # a = 1 / 0
    # 读取配置信息
    # 1. 直接从全局对象app的config字典取值
    # print(app.config['ITCAST'])
    # print(current_app.config.get('ITCAST'))

    return 'Hello world'


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

 

相关文章:

  • 2021-12-21
  • 2021-04-17
  • 2022-01-16
  • 2021-10-09
  • 2021-06-07
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2022-12-23
  • 2022-01-05
  • 2022-03-10
  • 2021-07-09
  • 2021-04-08
  • 2021-05-29
相关资源
相似解决方案