AJAX (bottle_utils.ajax)

The bottle_utils.ajax module provides decorators for working with AJAX requests.

Decorators

bottle_utils.ajax.ajax_only(func)[source]

Return HTTP 400 response for all non-XHR requests.

Warning

AJAX header (‘X-Requested-With’) can be faked, so don’t use this decorator as a security measure of any kind.

Example:

@ajax_only
def hidden_from_non_xhr():
    return "Foo!"
bottle_utils.ajax.roca_view(full, partial, **defaults)[source]

Render partal for XHR requests and full template otherwise. If template_func keyword argument is found, it is assumed to be a function that renders the template, and is used instead of the default one, which is bottle.template().

Note

To work around issues with Chrome browser (all platforms) when using this decorator in conjunction with HTML5 pushState, the decorator always adds a Cache-Control: no-store header to partial responses.

Example:

@roca_view('page.html', 'fragment.html')
def my_roca_handler():
    return dict()