ZCML 可以包含以下形式的条件指令
<configure zcml:condition="installed some.python.package">
(conditional configuration directives)
</configure>
的表达式语法是condition什么?是否允许使用“或”?
我也总是要查一下这个。语法很简单,or恐怕不是语法的一部分。
正如您从zope.configuration 源代码中的文档中看到的那样,语法始终为 形式,verb arguments其中动词是have、not-have和之一。installednot-installed
have并not-have测试已注册的功能。已注册的功能只是一个已使用<meta:provides feature="something" />标签注册的不透明字符串。使用它来标记已包含某些内容,而无需将其绑定到特定实现。例子:
<configure zcml:condition="have apidoc">
<!-- only when the apidoc feature has been provided -->
</configure>
installed并not-installed简单地尝试导入命名包;如果导入成功,installed测试也会成功。例子:
<configure zcml:condition="installed sqlalchemy">
<!-- only when the sqlalchemy module can be imported -->
</configure>