diff --git a/docs/source/main.md b/docs/source/main.md index 425916a..7c2dbc6 100644 --- a/docs/source/main.md +++ b/docs/source/main.md @@ -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 diff --git a/src/turbo_response/response.py b/src/turbo_response/response.py index 50a431b..1483894 100644 --- a/src/turbo_response/response.py +++ b/src/turbo_response/response.py @@ -14,7 +14,7 @@ class HttpResponseSeeOther(HttpResponseRedirect): - """Redirect with 303 status""" + """Obsolete: Redirect with 303 status""" status_code = http.HTTPStatus.SEE_OTHER diff --git a/src/turbo_response/shortcuts.py b/src/turbo_response/shortcuts.py index 5075685..d23109d 100644 --- a/src/turbo_response/shortcuts.py +++ b/src/turbo_response/shortcuts.py @@ -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()`. """