我遵循了《掌握烧瓶》一书中推荐的文件结构。在
(我的项目名称是Paw)
在Paw/paw/__init__.py
中:
def create_app(object_name):
app = Flask(__name__)
app.config.from_object(object_name)
db.init_app(app)
robot = LoggingWeRobot(token='banana', enable_session=True)
robot.init_app(app, endpoint='werobot', rule='/wechat')
attach_debugging_logger(app)
app.register_blueprint(poll_blueprint)
app.register_blueprint(wechat_blueprint)
return app
注意,robot变量实际上在我的蓝图微信中是需要的,可以在:Paw/Paw/controllers中找到/微信.py在
^{pr2}$所以我的问题是我的蓝图不能访问robot
变量。但是,robot
变量应该在Paw/paw/__init__.py
中的createapp中创建,因为我试图遵循applicationfactory模式。在
关于如何解决这个问题有什么建议吗?我的项目可以在here找到,我正试图遵循this application structure
我通常将项目全局变量放在一个文件中(比如
gvars.py
)。在项目结构如下:
在其他文件中,我们只需执行以下操作:
^{pr2}$只需使用与
db
-在别处创建robot
的相同模式,并将其导入到Paw/paw/__init__.py
文件中,就像使用db
一样:相关问题 更多 >
编程相关推荐