class mimerender.MimeRenderBase(global_default=None, global_override_arg_idx=None, global_override_input_key=None, global_charset=None, global_not_acceptable_callback=None)[source]
__call__(default=None, override_arg_idx=None, override_input_key=None, charset=None, not_acceptable_callback=None, **renderers)[source]

Main mimerender decorator. Usage:

@mimerender(default='xml', override_arg_idx=-1, override_input_key='format', , <renderers>)
GET(self, ...) (or POST, etc.)

The decorated function must return a dict with the objects necessary to render the final result to the user. The selected renderer will be called with the dict contents as keyword arguments. If override_arg_idx isn’t None, the wrapped function’s positional argument at that index will be used instead of the Accept header. override_input_key works the same way, but with web.input().


    default = 'xml',
    override_arg_idx = -1,
    override_input_key = 'format',
    xhtml   = xhtml_templates.greet,
    html    = xhtml_templates.greet,
    xml     = xml_templates.greet,
    json    = json_render,
    yaml    = json_render,
    txt     = json_render,
def greet(self, param):
    message = 'Hello, %s!'%param
    return {'message':message}
map_exceptions(mapping, *args, **kwargs)[source]

Exception mapping helper decorator. Takes the same arguments as the main decorator, plus mapping, which is a list of (exception_class, status_line) pairs.

Project Versions

Previous topic

Usage Examples

This Page