XBlock

class xblock.core.XBlock(runtime, model_data)

Base class for XBlocks.

Derive from this class to create a new kind of XBlock. There are no required methods, but you will probably need at least one view.

Don’t provide the __init__ method when deriving from this class.

runtime is an instance of xblock.core.Runtime. Use it to access the environment. It is available in XBlock code as self.runtime.

model_data is a dictionary-like interface to runtime storage. XBlock uses it to implement your storage fields.

classmethod json_handler(fn)

Wrap a handler to consume and produce JSON.

Rather than a Request object, the method will now be passed the JSON-decoded body of the request. Any data returned by the function will be JSON-encoded and returned as the response.

classmethod postprocess_input(node, usage_factory)

The class can adjust a parsed Usage tree.

classmethod preprocess_input(node, usage_factory)

The class can adjust a parsed Usage tree.

classmethod tag(tags)

Add the words in tags as class tags to this class.