載入專案常量配置物件

yongheng999發表於2024-07-17

這裡我們從本地類當中取值:

from flask import Flask

class DefaultConfig(object):
"""default project config"""
USER = "zhang"
PWD ="<PASSWORD>"



app=Flask(__name__)
app.config.from_object(DefaultConfig)



@app.route('/')
def index():
print(app.config['USER'])
print(app.config['PWD'])
return "Hello World!"


if __name__ == '__main__':
app.run()

相關文章