【发布时间】:2017-08-18 20:20:44
【问题描述】:
一旦我开始使用 Flask 工厂应用程序模式,我就会对配置和导入感到困惑。
我正在使用 #app/init.py 中的函数 create_app 创建一个应用程序 我有一个用于设置开发/测试/生产变量的配置文件,以及一个带有另一个配置文件的实例文件夹。
def create_app(config_name):
app=Flask(__name__, instance_relative_config=True)
app.config.from_object(app_config[config_name])
app.config.from_pyfile('config.py')
etc...
return app
我正在使用蓝图并在#app/auth/views.py 中有一个身份验证视图 我正在尝试使用 URLSafeTimedSerializer 设置电子邮件确认令牌...
from itsdangerous import URLSafeTimedSerializer
@auth.route('/register', methods=['GET','POST'])
def register():
ts = URLSafeTimedSerializer(app.config['SECRET_KEY'])
token = ts.dumps(self.email, salt='email-confirm-key')
etc...
现在我的问题是,我的变量 'ts' 需要设置 app.config['SECRET_KEY']。但我无法定义 app 变量(如所有在线教程中所示)。尝试导入时出现错误...(在 #app/auth/views.py 中)
from .. import app
当我尝试导入时...
from .. import create_app
有人可以阐明如何在烧瓶应用工厂 create_app 之外使用“app”和 app.config 初始化模块吗?
希望你能理解我的问题。
【问题讨论】:
标签: python flask token config factory