Python 在Kotti中可以有一个内容元素的多个通用子视图吗?

Python 在Kotti中可以有一个内容元素的多个通用子视图吗?,python,pyramid,kotti,Python,Pyramid,Kotti,通过执行以下操作,可以在kotti中为内容类型添加“视图”: from kotti_mysite.views import poll_view config.add_view( poll_view, context=Poll, name='view', permission='view', renderer='kotti_mysite:templates/poll.pt', ) (更多详情:) 您也可以有多个视图,并使用“设置默认视图”,但有时使用几个

通过执行以下操作,可以在kotti中为内容类型添加“视图”:

from kotti_mysite.views import poll_view

config.add_view(
    poll_view,
    context=Poll,
    name='view',
    permission='view',
    renderer='kotti_mysite:templates/poll.pt',
)
(更多详情:)

您也可以有多个视图,并使用“设置默认视图”,但有时使用几个具有非常相似URL的类似视图会很方便

例如,在plone中,具有如下url结构很简单:

from kotti.interfaces import IContent

config.add_view(
    my_json_view,
    context=IContent,
    name='json',
    permission='view',
    renderer='json',
)

  • /blah/item/您可以为所有内容注册json视图,如下所示:

    from kotti.interfaces import IContent
    
    config.add_view(
        my_json_view,
        context=IContent,
        name='json',
        permission='view',
        renderer='json',
    )
    
    这样,当您打开
    /blah/json
    ,其中
    /blah
    指向某些内容时,它将调用您的
    我的json_视图
    视图

    SQLAlchemy可能会帮助您编写一个适用于多种内容类型的有用的通用json视图。或者,您可以仅为特定内容类型注册视图(通过使用
    config.add\u view
    中更具体的
    上下文
    参数)

    使用
    renderer='json'
    告诉Pyramid您要使用它的