大佬教程收集整理的这篇文章主要介绍了在启动时查询注册表时的ComponentLookupError,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<include package="plone.app.registry" /> <include package="collective.lead" /> <i18n:registerTranslations directory="locales" /> <utility provides="collective.lead.interfaces.IDatabase" factory=".dbsetTings.CalculatorDatabase" name="test.calc.db" />
from zope.component import getUtility from plone.registry.interfaces import IRegistry class CalculatorDatabase(DatabasE): @property def _url(self): registry = getUtility(IRegistry) setTings = registry.forInterface(IDatabaseSetTings) return URL( drivername=setTings.drivername,username=setTings.username,password=setTings.password,host=setTings.hostname,port=setTings.port,database=setTings.database,)
这会在运行时引发ComponentLookupError异常:
File "/home/zope/envs/test-web/src/test.calc/test/calc/dbsetTings.py",line 38,in _url registry = getUtility(IRegistry) File "/home/zope/envs/test-web/eggs/zope.component-3.7.1-py2.6.egg/zope/component/_api.py",line 171,in getUtility raise ComponentLookupError(interface,Name) zope.configuration.config.ConfigurationExecutionError: <class 'zope.component.interfaces.ComponentLookupError'>: (<InterfaceClass plone.registry.interfaces.IRegistry>,'') in: File "/home/zope/envs/test-web/src/test.calc/test/calc/configure.zcml",line 26.2-30.6 <utility provides="collective.lead.interfaces.IDatabase" factory=".dbsetTings.CalculatorDatabase" name="test.calc.db" />
为什么在运行时找不到注册表?我究竟做错了什么?
谢谢.
解决方法是不在zcml中注册该实用程序,而是在以下订阅者中执行此操作:
<subscriber for="Products.CMFPlone.interfaces.IPlonesiteRoot zope.app.publication.interfaces.IBeforeTraverseEvent" handler=".component.setupstuff" />
这将保证setupstuff可以访问所有本地实用程序.另请注意,在查询实用程序是否已存在之后,setupstuff也会快速返回,因为订阅者将在每个请求上触发.
以上是大佬教程为你收集整理的在启动时查询注册表时的ComponentLookupError全部内容,希望文章能够帮你解决在启动时查询注册表时的ComponentLookupError所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。