在 pylons 中使用带有声明性语法的 repoze.what

发布于 2024-11-16 05:36:53 字数 898 浏览 0 评论 0原文

我正在 Pylons 中编写一个应用程序,我想添加一个授权方案。我选择了repoze.what。我按照 Pylons 食谱中的教程进行操作:

http://wiki.pylonshq。 com/display/pylonscookbook/Authorization+with+repoze.what

问题是在 lib/auth.py 中我需要包含用户、组的模型和许可。在模型中使用声明性基础,当我想要部署时,它会给我一个错误:

sqlalchemy.exc.UnboundExecutionError: No engine is bound to this Table's MetaData.
Pass an engine to the Table via autoload_with=<someengine>, or associate the MetaData
with an engine via metadata.bind=<someengine>

我在这里发现类似的问题:

SQLAlchemy 声明性语法与 Pylons 中的自动加载(反射)

我在单独的文件中声明了所有授权模型__init__.py。我也遵循了上述问题的所有指示,但仍然有问题。 有人找到解决方案了吗?

I'm writing an application in Pylons and I want to add an authorization scheme. I've chosen repoze.what. I followed the tutorial from Pylons cookbook:

http://wiki.pylonshq.com/display/pylonscookbook/Authorization+with+repoze.what

The problem is that in lib/auth.py I need to include models for User, Group and Permission. Using declarative base in model, it gives me an error when I want to deploy:

sqlalchemy.exc.UnboundExecutionError: No engine is bound to this Table's MetaData.
Pass an engine to the Table via autoload_with=<someengine>, or associate the MetaData
with an engine via metadata.bind=<someengine>

I found similar problem here:

SQLAlchemy declarative syntax with autoload (reflection) in Pylons

I have all the models for authorization declared in a separate file from __init__.py. I also followed all indications from above question but there is still something wrong.
Anyone found a solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请恋爱 2024-11-23 05:36:53

我想我找到了解决方案。我只是在包含授权模型的模块中创建一个引擎,并将其绑定到元数据。我不知道为什么 init_model 不自己这样做。所以这不是声明性语法的问题。抱歉给您带来不便。

I think I found a solution. I just create an engine in the module that contains models for authorization and I bind it to the metadata. I have no idea why init_model does not do this on its own. So this is not a problem of declarative syntax. Sorry for inconvenience.

简单气质女生网名 2024-11-23 05:36:53

在模型 __init__.py 中,您需要将引擎绑定到会话。

def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    ## Reflected tables must be defined and mapped here
    #global reflected_table
    #reflected_table = sa.Table("Reflected", meta.metadata, autoload=True,
    #                           autoload_with=engine)
    #orm.mapper(Reflected, reflected_table)

    session = orm.sessionmaker(bind=engine, autoflush=True, autocommit=False)
    meta.metadata.bind = engine
    meta.engine = engine
    meta.Session = orm.scoped_session(session)

资源:
http://docs.pylonsproject.org/projects/pylons_framework/dev/advanced_models.html

In the model __init__.py you need to bind the engine to the session.

def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    ## Reflected tables must be defined and mapped here
    #global reflected_table
    #reflected_table = sa.Table("Reflected", meta.metadata, autoload=True,
    #                           autoload_with=engine)
    #orm.mapper(Reflected, reflected_table)

    session = orm.sessionmaker(bind=engine, autoflush=True, autocommit=False)
    meta.metadata.bind = engine
    meta.engine = engine
    meta.Session = orm.scoped_session(session)

Resources:
http://docs.pylonsproject.org/projects/pylons_framework/dev/advanced_models.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文