Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update doc #14

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions docs/source/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,26 +320,16 @@ to ensure the FormData object includes the button value.

## Redirects

As per the [documentation](https://turbo.hotwire.dev/handbook/drive#redirecting-after-a-form-submission), Turbo expects a 303 redirect after a form submission. While this does not appear to be a hard-and-fast rule, you should probably have your view return a 303 instead of a 301 or 302 after a form submission. This package includes a class **turbo_response.HttpResponseSeeOther** and a shortcut **redirect_303** for returning the correct status with a redirect. The form mixin and view classes will return a 303 redirect by default.
As per the [documentation](https://turbo.hotwire.dev/handbook/drive#redirecting-after-a-form-submission), Turbo expects a 303 redirect after a form submission.

```python
from turbo_response import HttpResponseSeeOther

def my_view(request):
form = MyForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseSeeOther("/")
```
If your project has `PUT`, `PATCH`, `DELETE` requests, then you might need to take a look at this [Clarification on redirect status code (303)](https://github.com/hotwired/turbo/issues/84#issuecomment-862656931)

Note that the **redirect_303** shortcut works the same way as **django.shortcuts.redirect**: you can use a view name with arguments, a URL string, or a model which has a `get_absolute_url()` method:
In Django, you can do it like this:

```python
from turbo_response import redirect_303
from django.shortcuts import redirect

redirect_303("/")
redirect_303("blog_detail", id=1, slug=blog.title)
redirect_303(blog)
return redirect('https://example.com/', status=303)
```

## Responding with Multiple Streams
Expand Down
2 changes: 1 addition & 1 deletion src/turbo_response/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class HttpResponseSeeOther(HttpResponseRedirect):
"""Redirect with 303 status"""
"""Obsolete: Redirect with 303 status"""

status_code = http.HTTPStatus.SEE_OTHER

Expand Down
2 changes: 1 addition & 1 deletion src/turbo_response/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def redirect_303(to: Union[str, Model], *args, **kwargs) -> HttpResponseSeeOther:
"""Sends an HTTP 303 redirect.
"""Obsolete: Sends an HTTP 303 redirect.

:param to: URL or view name or model instance. If model then calls `get_absolute_url()`.
"""
Expand Down