Page Metadata

Set a page's title, meta tags, stylesheets, and scripts in the Python controller's initial render. The metadata field on RenderBase controls the page's HTML <head>:

class Metadata(BaseModel):
    title: str | None = None
    metas: list[MetaAttribute] = []
    links: list[LinkAttribute] = []
    scripts: list[ScriptAttribute] = []

Title

Return a Metadata instance from render() to set the title. You can use values fetched by the controller, such as an account name or unread message count:

class MyRender(RenderBase):
    pass

def render() -> MyRender:
    return MyRender(
        metadata=Metadata(
            title="My Title"
        )
    )

Use MetaAttribute and LinkAttribute to describe <meta> and <link> elements. Their values can follow browser or crawler conventions, as in this meta tag:

class MyRender(RenderBase):
    pass

def render() -> MyRender:
    return MyRender(
        metadata=Metadata(
            metas=[
                MetaAttribute(
                    name="og:meta",
                    content="Some meta content",
                )
            ]
        )
    )

Helper constructors cover some structured meta values, such as viewport settings. See the Controller API docs for the available types.

Scripts

You can also inject <script> tags through metadata. This is useful for analytics, third-party widgets, or small bits of bootstrap logic that need to run before your app hydrates.

For external scripts, use src:

def render() -> MyRender:
    return MyRender(
        metadata=Metadata(
            scripts=[
                ScriptAttribute(
                    src="https://example.com/widget.js",
                    defer=True,
                )
            ]
        )
    )

For inline scripts, use inline:

def render() -> MyRender:
    return MyRender(
        metadata=Metadata(
            scripts=[
                ScriptAttribute(
                    inline="window.APP_BOOTSTRAPPED = true;",
                )
            ]
        )
    )

ScriptAttribute requires exactly one of src or inline. You can also pass standard attributes like defer, asynchronous, or extra values through optional_attributes.

Global Metadata

Set global_metadata on AppController for stylesheets or scripts that every page needs:

controller = AppController(
    global_metadata=Metadata(
        links=[LinkAttribute(rel="stylesheet", href="/static/main.css")],
        scripts=[ScriptAttribute(src="https://example.com/app.js", defer=True)],
    ),
)