Server

Server.get_running_views_count()

lona.server.LonaServer.get_running_views_count(
    self,
    user: 'Any',
) -> int
    Returns the count of running views for the given user as integer.

Server.view_is_already_running()

lona.server.LonaServer.view_is_already_running(
    self,
    request: 'Request',
) -> bool
    Checks if a view for the given request is already running and returns
    a boolean.

    :request:  (lona.request.Request)

Server.get_connection_count()

lona.server.LonaServer.get_connection_count(
    self,
    user: 'Any',
) -> int
    Returns the count of connections for the given user as integer.

    :user: user object

Server.get_connected_user_count()

lona.server.LonaServer.get_connected_user_count(
    self,
) -> int
    Returns the count of connected users as integer.

Server.get_template()

lona.server.LonaServer.get_template(
    self,
    template_name: 'str',
) -> Template
    Returns a Jinja2 template object associated with the given template
    name.

Server.render_string()

lona.server.LonaServer.render_string(
    self,
    template_string: 'str',
    template_context: 'dict | None' = None,
) -> str
    Takes a Jinja2 template as a string and returns the rendering result
    as string. If no template context is given, an empty one is used.

    All values in settings.TEMPLATE_EXTRA_CONTEXT get added to the
    template context before rendering.

    :template_string:  (str) Jinja2 template as string
    :template_context: (dict|none) template context as dictionary

Server.render_template()

lona.server.LonaServer.render_template(
    self,
    template_name: 'str',
    template_context: 'dict | None' = None,
) -> str
    Takes the name of a Jinja2 template as a string, searches for a
    matching template in settings.TEMPLATE_DIRS and returns the rendering
    result as string. If no template context is given, an empty
    one is used.

    All values in settings.TEMPLATE_EXTRA_CONTEXT get added to the
    template context before rendering.

    :template_name:    (str) Jinja2 template as string
    :template_context: (dict|none) template context as dictionary

Server.get_view_class()

lona.server.LonaServer.get_view_class(
    self,
    route_name: 'str | None' = None,
    route: 'Route | None' = None,
    import_string: 'str | None' = None,
    url: 'str | None' = None,
) -> type[LonaView] | None
    Returns the lona.view.LonaView subclass associated with the given
    route_name, route, import string or url.

    Only one argument can be set at a time.

Server.get_views()

Note

Added in 1.9

lona.server.LonaServer.get_views(
    self,
    route_name: 'str | None' = None,
    route: 'Route | None' = None,
    import_string: 'str | None' = None,
    url: 'str | None' = None,
    user: 'Any' = None,
) -> list[LonaView]
    Returns a list of all running Lona views associated with the given
    route_name, route, import string or url.

    Only one argument to find the view can be set at a time. User can
    always be set.

    :route:          (lona.Route|none) Lona route associated with the view
    :import_string:  (str|none) import string of the view
    :url:            (str|none) URL to the view
    :user:           (any) User that runs th view (optional)

Server.reverse()

Note

The argument name was renamed to route_name in 1.8

lona.server.LonaServer.reverse(
    self,
    route_name: 'str',
    *args: 'Any',
    **kwargs: 'dict[str, Any]',
) -> str
    Returns a routing reverse match as string.

    :route_name:  (str) route name as string
    :args:        route arguments
    :kwargs:      route keyword argument

Server.fire_view_event()

Note

Added in 1.7.3

lona.server.LonaServer.fire_view_event(
    self,
    name: 'str',
    data: 'dict | None' = None,
    view_classes: 'type[LonaView] | list[type[LonaView]] | None' = None,
) -> None
    Sends a view event to all objects of the given LonaView class.
    If view_classes is not set, the event becomes a broadcast event and
    gets send to all view classes.

    :name: has to be a str, data is optional but has to be a dict if set.
    :view_classes: can be a single view class or a list of view classes.

    Examples:

        # broadcast event
        server.fire_view_event('foo', {'foo': 'bar'})

        # event for all view objects behind the URL '/foo'
        server.fire_view_event(
            'foo',
            {'foo': 'bar'},
            view_classes=server.get_view_class(url='/foo'),
        )

Server.embed_shell()

Note

Removed in 1.8. Use rlpython directly instead.

import rlpython
rlpython.embed()

Embeds a rlpython based shell in the server context. More info on shells: Debugging.