Install & Compatibility
Where this runs
tested against v4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.028s · 19.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.1s · import 0.024s · 20MB
22MB installed
● package 22MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
IBrowserView
✓ from zope.browser.interfaces import IBrowserView
BrowserView
✓ from zope.publisher.browser import BrowserView
✗ from zope.browser.publisher import BrowserView
While `zope.browser.publisher` exists, the canonical base class for browser views is now `zope.publisher.browser.BrowserView` since `zope.publisher` handles the core publishing logic.
Resource
✓ from zope.browser.resource import Resource
This example demonstrates how to define a basic `IBrowserView` and its implementation `MyBrowserView` which inherits from `zope.publisher.browser.BrowserView`. It shows how views typically access `self.context` (the object being viewed) and `self.request` (the HTTP request). The `if __name__ == '__main__':` block illustrates how a view is instantiated with dummy context and request objects for testing purposes, mimicking the behavior of the Zope publisher.
import zope.interface
import zope.schema
import zope.publisher.browser
# 1. Define an interface for the content we want to view
class IMyContent(zope.interface.Interface):
"""An interface for some content object."""
title = zope.schema.TextLine(title="Title")
# 2. Define a simple content object that implements the interface
@zope.interface.implementer(IMyContent)
class MyContent:
def __init__(self, title="Default Content"): # pragma: no cover
self.title = title
# 3. Define the browser view
class MyBrowserView(zope.publisher.browser.BrowserView):
"""A simple browser view that uses context and request."""
def __call__(self):
# self.context is the content object
# self.request is the HTTP request
return f"<h1>Hello from {self.context.title}!</h1>"
def get_message(self):
return f"View message for {self.context.title}"
# Example of instantiating and using the view for testing/demonstration
# In a real Zope application, this would be handled by the Zope publisher.
if __name__ == "__main__":
from zope.publisher.interfaces.http import IHTTPRequest
from zope.interface.declarations import implementer
@implementer(IHTTPRequest)
class DummyRequest: # pragma: no cover
# Minimal request object for instantiation
pass
content = MyContent(title="My Awesome Page")
request = DummyRequest()
view = MyBrowserView(context=content, request=request)
print(view()) # Output: <h1>Hello from My Awesome Page!</h1>
print(view.get_message()) # Output: View message for My Awesome Page
Errors
Common errors & fixes
zope.component.interfaces.ComponentLookupError: ('No matching adapter found for (...), None, ...')
The Zope Component Architecture could not find a suitable browser view registered for the given combination of context, request, and view name.
fixVerify your ZCML or programmatic `zope.component.provideAdapter` registrations. Ensure an adapter is provided for the exact interfaces of your context and request, and the correct view name, implementing `IBrowserView`.
TypeError: __init__() missing 2 required positional arguments: 'context' and 'request'
You are attempting to directly instantiate a `BrowserView` (or a class inheriting from it) without providing the mandatory `context` and `request` arguments to its constructor.
fixWhen manually instantiating a view (e.g., in tests), always pass both `context` and `request` objects: `MyView(context=my_content_object, request=my_request_object)`. In a live Zope application, the publisher handles this.
AttributeError: 'MyBrowserView' object has no attribute 'request'
This usually indicates that the `request` object (or `context`) was not correctly passed to the `BrowserView` constructor, or `super().__init__(context, request)` was not called in a subclass's `__init__` method.
fixEnsure that your view class's `__init__` method (if overridden) explicitly calls `super().__init__(context, request)`. If not overridden, ensure that the `BrowserView` is instantiated with both arguments.
Upgrade
Version history
4.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredCore dependency for defining interfaces and adapting objects, fundamental to Zope's component architecture.
zope.locationrequiredProvides traversal mechanisms and location awareness for objects within a Zope application.
zope.publisherrequiredDefines the publishing mechanism and base classes for HTTP requests and responses, which browser views interact with.
zope.schemarequiredUsed for defining typed attributes in interfaces, often for form fields or data validation.
zope.securityrequiredProvides security mechanisms, including permission checking for views and other components.