API Reference¶
- class turbo_flask.Turbo(app=None)¶
- turbo(version='8.0.11', url=None)¶
Add turbo.js to the page.
This method is accessible in template files as
turbo. You must add{{ turbo() }}in the<head>section of your main template to activate turbo.js.- Parameters:
version – the version of turbo.js to load.
url – The URL for the turbo.js library, or
Noneto use the default version and CDN.
- user_id(f)¶
Configure an application-specific user id generator, to allow the application to push updates over WebSocket to individual clients.
Example:
@turbo.user_id def get_user_id(): return current_user.id
- default_user_id()¶
Default user id generator. An application-specific function can be configured with the
@user_iddecorator.
- requested_frame()¶
Returns the target frame the client expects, or
None.
- can_stream()¶
Returns
Trueif the client accepts turbo stream reponses.
- can_push(to=None)¶
Returns
Trueif the client accepts turbo stream updates over WebSocket.- Parameters:
to – the id of the client. If not given then the answer is
Trueif there is at least one client listening to updates over WebSocket.
- append(content, target, multiple=False)¶
Create an append stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID or CSS query selector for this change.
multiple – set to
Truewhentargetreferences multiple elements.
- prepend(content, target, multiple=False)¶
Create a prepend stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID or CSS query selector for this change.
multiple – set to
Truewhentargetreferences multiple elements.
- replace(content, target, multiple=False)¶
Create a replace stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID or CSS query selector for this change.
multiple – set to
Truewhentargetreferences multiple elements.
- update(content, target, multiple=False)¶
Create an update stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID or CSS query selector for this change.
multiple – set to
Truewhentargetreferences multiple elements.
- remove(target, multiple=False)¶
Create a remove stream.
- Parameters:
target – the target ID or CSS query selector for this change.
multiple – set to
Truewhentargetreferences multiple elements.
- after(content, target, multiple=False)¶
Create an after stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID or CSS query selector for this change.
multiple – set to
Truewhentargetreferences multiple elements.
- before(content, target, multiple=False)¶
Create an before stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID or CSS query selector for this change.
multiple – set to
Truewhentargetreferences multiple elements.
- stream(stream)¶
Create a turbo stream response.
- Parameters:
stream – one or a list of streamed responses generated by the
append(),prepend(),replace(),update()andremove()methods.
- push(stream, to=None)¶
Push a turbo stream update over WebSocket to one or more clients.
- Parameters:
stream – one or a list of stream updates generated by the
append(),prepend(),replace(),update()andremove()methods.to – the id of the target client. Set to
Noneto send to all connected clients, or to a list of ids to target multiple clients.