Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-yin committed Jan 25, 2024
1 parent 158ef32 commit 84faeb3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions docs/source/multi-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ We can do similar approach with `turbo_helper`

```python
from turbo_helper import (
ResponseFormat,
response_format,
TurboStreamResponse,
respond_to,
)

class TaskCreateView(LoginRequiredMixin, CreateView):
Expand All @@ -39,18 +39,18 @@ class TaskCreateView(LoginRequiredMixin, CreateView):
messages.success(request, "Created successfully")

with respond_to(request) as resp_format:
if resp_format.html:
return response
if resp_format.turbo_stream:
return TurboStreamResponse(
render_to_string(
"demo_tasks/partial/task_create_success.turbo_stream.html",
context={
"form": TaskForm(),
},
request=self.request,
),
)
if resp_format.turbo_stream:
return TurboStreamResponse(
render_to_string(
"task_create_success.turbo_stream.html",
context={
"form": TaskForm(),
},
request=self.request,
),
)
if resp_format.html:
return response
```

Notes:
Expand Down

0 comments on commit 84faeb3

Please sign in to comment.