Python 在Kotti中可以有一个内容元素的多个通用子视图吗?
通过执行以下操作,可以在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', ) (更多详情:) 您也可以有多个视图,并使用“设置默认视图”,但有时使用几个
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
视图 SQLAlchemy可能会帮助您编写一个适用于多种内容类型的有用的通用json视图。或者,您可以仅为特定内容类型注册视图(通过使用我的json_视图
中更具体的config.add\u view
参数) 使用上下文
告诉Pyramid您要使用它的renderer='json'