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 andfull
template otherwise. Iftemplate_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 isbottle.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()