• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 6.x
    2. Version 6.x
    3. Version 5.x
    4. Version 4.x
    5. Version 3.x
    6. Version 2.x
    7. Version 2.0
    8. Version 1.0
    9. Version 0.9
    10. Djblets Documentation
    11. Module and Class References
    12. djblets.pagestate.state
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Caching Guides
  • Caching Data
  • Working with Cache Keys
  • Cache Backends
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Dynamic Page Injections
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • Protection Guides
  • Rate Limiting Operations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.comma_separated_values_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.query_catcher
  • djblets.db.query_comparator
  • djblets.db.validators
  • djblets.pagestate
  • djblets.pagestate.injectors
  • djblets.pagestate.middleware
  • djblets.pagestate.state
  • djblets.pagestate.templatetags.djblets_pagestate
  • djblets.extensions
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.requests
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.protect
  • djblets.protect.locks
  • djblets.protect.ratelimit
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • djblets.pagestate.state¶

    Page state representations.

    New in version 6.0.

    class PageStateData[source]¶

    Bases: TypedDict

    Data to inject into a page

    This represents content for the page (as HTML-safe or unsafe text) and an ETag to include with the page response. Both are optional.

    New in version 6.0.

    content: NotRequired[SafeString | str]¶

    The content to include in the page.

    This can be HTML-safe or unsafe text.

    etag: NotRequired[str | None]¶

    The ETag data to include for the HTTP response.

    __annotations__ = {'content': ForwardRef('NotRequired[SafeString | str]', module='djblets.pagestate.state'), 'etag': ForwardRef('NotRequired[str | None]', module='djblets.pagestate.state')}¶
    __closed__ = None¶
    __extra_items__ = typing_extensions.NoExtraItems¶
    __mutable_keys__ = frozenset({'content', 'etag'})¶
    __optional_keys__ = frozenset({})¶
    __orig_bases__ = (typing_extensions.TypedDict,)¶
    __readonly_keys__ = frozenset({})¶
    __required_keys__ = frozenset({'content', 'etag'})¶
    __total__ = True¶
    class PageState[source]¶

    Bases: object

    Additional state used for the dynamic construction of a page.

    This is used to dynamically inject content into a page. Pages can make use of {% page_hook_point %} template tags to specify places where content can be injected.

    Content can be injected in two ways:

    1. Manually through calls to :py:meth:inject`.

    2. Dynamically by calling registered injectors, which take a page hook point name and provide the data to inject.

    Both content for the page and ETags for the response can be injected.

    If the same named page hook point is used in multiple places, or across multiple template renders within a request/response cycle, each point will contain the injected content.

    Callers can also store and retrieve arbitrary data using the extra_data attribute. This will not affect page rendering or ETags.

    New in version 6.0.

    classmethod for_request(request: HttpRequest, *, only_if_exists: Literal[True]) → Self | None[source]¶
    classmethod for_request(request: HttpRequest, *, only_if_exists: Literal[False] = False) → Self

    Return a PageState for a given HTTP request.

    The same instance will be returned every time this is called for the same HTTP request.

    Parameters:
    • request (django.http.HttpRequest) – The HTTP request from the client.

    • only_if_exists (bool, optional) –

      If set, this will return None if data doesn’t already exist.

      By default, an instance will always be returned.

    Returns:

    The page state instance for the request.

    Return type:

    PageState

    __init__() → None[source]¶

    Initialize the page state.

    extra_data: dict[str, Any]¶

    A dictionary callers can use for arbitrary storage of data.

    __annotations__ = {'_data': 'dict[str, list[PageStateData]]', '_etag_sha': '_Hash | None', 'extra_data': 'dict[str, Any]'}¶
    inject(point_name: str, data: PageStateData) → None[source]¶

    Manually inject data into the page.

    This may contain content for the page hook point, and it may contain ETag data to include in the final ETag.

    Parameters:
    • point_name (str) – The page hook point name to inject data into.

    • data (PageStateData) – The data to inject into the page hook point.

    Raises:

    ValueError – The page state data was missing a required key or contained an incorrect type.

    clear_injections(point_name: str | None = None) → None[source]¶

    Clear injections for one or all page hook points.

    If a point name isn’t provided, manual injections will be cleared from all points.

    Parameters:

    point_name (str, optional) – The optional page hook point name to clear injections from.

    get_etag() → str[source]¶

    Return the current ETag for the page.

    If called while the page is still being rendered, future calls may have a different result.

    Returns:

    The current ETag for the data on the page.

    Return type:

    str

    iter_content(*, point_name: str, request: HttpRequest, context: Context) → Iterator[SafeString | str][source]¶

    Iterate through rendered content for a page hook point.

    This will first iterate through all dynamic injectors and then through all manual injections in order.

    Any missing ETags will be generated based on the page content, ensuring that changes in content will cause caches to invalidate.

    Any errors coming from an injector will be logged and the injector skipped.

    Parameters:
    • point_name (str) – The page hook point name to iterate through.

    • request (django.http.HttpRequest) – The HTTP request from the client.

    • context (django.template.Context) – The context for the template.

    Yields:

    str or django.utils.safestring.SafeString – Each HTML-safe or unsafe content injected into the page hook point.

    iter_page_state_data(*, point_name: str, request: HttpRequest, context: Context) → Iterator[PageStateData][source]¶

    Iterate through all page state data for a page hook point.

    This will first iterate through all dynamic injectors and then through all manual injections in order.

    Any errors coming from an injector will be logged and the injector skipped.

    Parameters:
    • point_name (str) – The page hook point name to iterate through.

    • request (django.http.HttpRequest) – The HTTP request from the client.

    • context (django.template.Context) – The context for the template.

    Yields:

    str or django.utils.safestring.SafeString – Each HTML-safe or unsafe content injected into the template hook point.

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube
    Copyright © 2006-2026 Beanbag, Inc. All rights reserved.
    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • PageStateData
      • PageStateData.content
      • PageStateData.etag
      • PageStateData.__annotations__
      • PageStateData.__closed__
      • PageStateData.__extra_items__
      • PageStateData.__mutable_keys__
      • PageStateData.__optional_keys__
      • PageStateData.__orig_bases__
      • PageStateData.__readonly_keys__
      • PageStateData.__required_keys__
      • PageStateData.__total__
    • PageState
      • PageState.for_request()
      • PageState.__init__()
      • PageState.extra_data
      • PageState.__annotations__
      • PageState.inject()
      • PageState.clear_injections()
      • PageState.get_etag()
      • PageState.iter_content()
      • PageState.iter_page_state_data()