zope.ptresource
raw JSON → 6.0 verified Mon Apr 27 auth: no python
Page template resource plugin for zope.browserresource. Version 6.0 supports Python >=3.9. Provides a way to register page templates as browser resources using ZCML directives. Release cadence is low, maintained by Zope Foundation.
pip install zope.ptresource Common errors
error zope.configuration.config.ConfigurationError: ('Unknown directive', u'http://namespaces.zope.org/zope', u'ptresource') ↓
cause The package's meta.zcml has not been included before using the ptresource directive.
fix
Add <include package="zope.ptresource" file="meta.zcml" /> in your configure ZCML.
error TypeError: __init__() got an unexpected keyword argument 'layer' ↓
cause Using deprecated integer layer parameter in ZCML with newer version that expects layer_name.
fix
Replace layer="123" with layer_name="some_name" or a dotted path to a layer interface.
Warnings
breaking Version 6.0 drops support for Python 2 and Python <3.9. Upgrade your Python version if you are on older releases. ↓
fix Ensure Python >=3.9 and upgrade the library.
deprecated The 'layer' attribute in ZCML ptresource directive is deprecated in favor of 'layer_name' (string) or 'layer' as a dotted name. Using integer layer IDs is no longer supported. ↓
fix Use layer_name='default' instead of layer='default' if using ZCML.
gotcha Missing include of 'meta.zcml' will cause unknown directive error. The ptresource directive is not available until the meta.zcml is loaded. ↓
fix Add <include package="zope.ptresource" file="meta.zcml" /> before using ptresource directive.
Imports
- PageTemplateResource
from zope.ptresource import PageTemplateResource
Quickstart
# Example ZCML registration (configure.zcml)
<configure xmlns="http://namespaces.zope.org/zope">
<include package="zope.ptresource" file="meta.zcml" />
<ptresource
name="my_template"
template="my_template.pt"
for="*"
layer="default"
/>
</configure>