V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yoyicue
V2EX  ›  Flask

关于 blueprints 的困扰

  •  
  •   yoyicue ·
    yoyicue · 2012-08-23 21:27:07 +08:00 · 3518 次点击
    这是一个创建于 4235 天前的主题,其中的信息可能已经有所发展或是发生改变。
    今年夏天之后的项目开始使用 Factories 和 Blueprints
    因为在 Factories 中已经无法访问 app objects
    所以在 Blueprints views 的 context 中使用 current_app
    其实也还好, 比如可以用类似下面的方式在view context 访问 db

    from werkzeug import LocalProxy
    from flask import current_app
    db = LocalProxy(lambda: current_app.extensions['sqlalchemy'])

    但是我突然也想在 Blueprints 下的 models 采用类似的相对方式.
    需求:

    1) 不用 from appname.extensions import db
    2) 但 current_app 这里无法使用 context
    3) 希望 Blueprints 能够完全脱离 appname 存在

    有解么?
    是不是有点怪诞的需求?
    1 条回复    1970-01-01 08:00:00 +08:00
    yoyicue
        1
    yoyicue  
    OP
       2012-08-23 23:29:20 +08:00
    再读了几遍文档, 觉得是 factory function 不够好 :(
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2752 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:58 · PVG 19:58 · LAX 04:58 · JFK 07:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.