A Runtime object is passed to the XBlock constructor. It has methods for interacting with the XBlock’s environment.

class xblock.runtime.Runtime

Access to the runtime environment for XBlocks.

A pre-configured instance of this class will be available to XBlocks as self.runtime.


Get a block by ID.

Returns the block identified by block_id, or raises an exception.


Get the actual URL to invoke a handler.

url is the abstract URL to your handler. It should start with the name you used to register your handler.

The return value is a complete absolute URL that will route through the runtime to your handler.


Query for data in the tree, starting from block.

Returns a Query object with methods for navigating the tree and retrieving information.

querypath(block, path)

An XPath-like interface to query.

render(block, context, view_name)

Render a block by invoking its view.

Finds the view named view_name on block. The default view will be used if a specific view hasn’t be registered. If there is no default view, an exception will be raised.

The view is invoked, passing it context. The value returned by the view is returned, with possible modifications by the runtime to integrate it into a larger whole.

render_child(child, context, view_name=None)

A shortcut to render a child block.

Use this method to render your children from your own view function.

If view_name is not provided, it will default to the view name you’re being rendered with.

Returns the same value as render().

render_children(block, context, view_name=None)

Render a block’s children, returning a list of results.

Each child of block will be rendered, just as render_child() does.

Returns a list of values, each as provided by render().