V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yoyicue
V2EX  ›  Flask

关于 blueprints 的困扰

  •  
  •   yoyicue ·
    yoyicue · Aug 23, 2012 · 4461 views
    This topic created in 5005 days ago, the information mentioned may be changed or developed.
    今年夏天之后的项目开始使用 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 replies    1970-01-01 08:00:00 +08:00
    yoyicue
        1
    yoyicue  
    OP
       Aug 23, 2012
    再读了几遍文档, 觉得是 factory function 不够好 :(
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1098 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:03 · PVG 02:03 · LAX 11:03 · JFK 14:03
    ♥ Do have faith in what you're doing.