API Reference¶
- class turbo_flask.Turbo(app=None)¶
- turbo(version='7.3.0', 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
None
to 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_id
decorator.
- requested_frame()¶
Returns the target frame the client expects, or
None
.
- can_stream()¶
Returns
True
if the client accepts turbo stream reponses.
- can_push(to=None)¶
Returns
True
if the client accepts turbo stream updates over WebSocket.- Parameters:
to – the id of the client. If not given then the answer is
True
if there is at least one client listening to updates over WebSocket.
- append(content, target)¶
Create an append stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID for this change.
- prepend(content, target)¶
Create a prepend stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID for this change.
- replace(content, target)¶
Create a replace stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID for this change.
- update(content, target)¶
Create an update stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID for this change.
- remove(target)¶
Create a remove stream.
- Parameters:
target – the target ID for this change.
- after(content, target)¶
Create an after stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID for this change.
- before(content, target)¶
Create an before stream.
- Parameters:
content – the HTML content to include in the stream.
target – the target ID for this change.
- 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
None
to send to all connected clients, or to a list of ids to target multiple clients.