Installation#

Requirements#

This library requires Python 3.8+ and Django 3.2+.

Getting Started#

pip install django-turbo-response

Next update INSTALLED_APPS:

INSTALLED_APPS = [
  "turbo_response",
  ...
]

Note: This install does not include any client libraries (e.g. Turbo or Stimulus). You may wish to add these yourself using your preferred Javascript build tool, or use a CDN. Please refer to the Hotwire documentation on installing these libraries.

Middleware#

You can optionally install turbo_response.middleware.TurboMiddleware. This adds the attribute turbo to your request if the Turbo client adds Accept: text/vnd.turbo-stream.html; to the header:

MIDDLEWARE = [
    ...
    "turbo_response.middleware.TurboMiddleware",
    "django.middleware.common.CommonMiddleware",
    ...
]

This is useful if you want to check if a stream is requested, so you can optionally return a stream or a normal response:

if request.turbo:
    # return Turbo Stream
else:
    # return normal response

If the request originates from a turbo-frame it will also set the frame property:

if request.turbo.frame == "my-playlist":
    pass