Plone 当尝试创建新的灵巧对象时,ComponentLookSuperRor

Plone 当尝试创建新的灵巧对象时,ComponentLookSuperRor,plone,dexterity,Plone,Dexterity,下面我将介绍如何操作灵巧内容对象。它解释了如何创建对象 从zope.component导入createObject context=createObject('example.type') 但是我不知道该放什么来代替example.type。我尝试使用ipproduct,degu.product.ipproduct和degu.product。但他们都提出了一个组成部分 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 createObject中的文件“/home/daniel/.build

下面我将介绍如何操作灵巧内容对象。它解释了如何创建对象

从zope.component导入createObject
context=createObject('example.type')
但是我不知道该放什么来代替
example.type
。我尝试使用
ipproduct
degu.product.ipproduct
degu.product
。但他们都提出了一个组成部分

回溯(最近一次呼叫最后一次):
文件“”,第1行,在
createObject中的文件“/home/daniel/.buildout/eggs/zope.component-3.9.5-py2.6.egg/zope/component/_api.py”,第220行
返回getUtility(IFactory、工厂名称、上下文)(*args、**kwargs)
文件“/home/daniel/.buildout/eggs/zope.component-3.9.5-py2.6.egg/zope/component/_-api.py”,第169行,在getUtility中
raise ComponentLookupError(接口、名称)
ComponentLookupError:(,“degu.commerce.product.ipproduct”)

您需要使用在中使用的相同名称

您可以验证在
portal\u type
工具中注册的名称:

from Products.CMFCore.utils import getToolByName

typestool = getToolByName(context, 'portal_types')
print typestool.listContentTypes()
或者访问浏览器中ZMI中的
portal_types
工具,查看那里的类型列表;它们在工具中列为
typeid(Type Title)
。如果没有列出您的类型,请确保首先正确注册您的类型

请注意,要使其工作,需要正确设置本地组件管理器。通常,这会自动发生,但如果您使用
bin/instance运行脚本或使用
bin/instance调试
,则不会发生这种情况。在这种情况下,您需要手动执行此操作:

from zope.app.component.hooks import setSite
from Testing.makerequest import makerequest

app = makerequest(app)
site = app[site_id]
setSite(site)
您可能还需要设置当前用户:

from AccessControl.SecurityManagement import newSecurityManager

user = app.acl_users.getUser('admin').__of__(site.acl_users)
newSecurityManager(None, user)

您需要使用在中使用的相同名称

您可以验证在
portal\u type
工具中注册的名称:

from Products.CMFCore.utils import getToolByName

typestool = getToolByName(context, 'portal_types')
print typestool.listContentTypes()
或者访问浏览器中ZMI中的
portal_types
工具,查看那里的类型列表;它们在工具中列为
typeid(Type Title)
。如果没有列出您的类型,请确保首先正确注册您的类型

请注意,要使其工作,需要正确设置本地组件管理器。通常,这会自动发生,但如果您使用
bin/instance运行脚本或使用
bin/instance调试
,则不会发生这种情况。在这种情况下,您需要手动执行此操作:

from zope.app.component.hooks import setSite
from Testing.makerequest import makerequest

app = makerequest(app)
site = app[site_id]
setSite(site)
您可能还需要设置当前用户:

from AccessControl.SecurityManagement import newSecurityManager

user = app.acl_users.getUser('admin').__of__(site.acl_users)
newSecurityManager(None, user)

内容类型
degu.Product
已列出,但我在尝试使用它时遇到了相同的错误。另外,使用
bin/instance debug
时未定义上下文,因此我使用app.Plone来获取typestool。@DanielHernández:啊,使用
bin/instance debug
不会设置本地组件管理器。这是一个不同的问题。对于
bin/instance run
@DanielHernández,我有同样的问题:我在更新的回答中明确指出,这适用于
debug
run
。列出了内容类型
degu.Product
,但我在尝试使用它时遇到了相同的错误。另外,使用
bin/instance debug
时未定义上下文,因此我使用app.Plone来获取typestool。@DanielHernández:啊,使用
bin/instance debug
不会设置本地组件管理器。这是一个不同的问题。我在
bin/instance run
@DanielHernández遇到了同样的问题:我在更新的回答中明确指出,这适用于
debug
run