68👍
For CBV:
from django.http import HttpResponseRedirect
return HttpResponseRedirect(self.request.path_info)
For function view:
from django.http import HttpResponseRedirect
return HttpResponseRedirect(request.path_info)
25👍
You can achieve this by redirecting to HTTP_REFERER
header and for fallback just add another path.
Example snippet:
return redirect(request.META.get('HTTP_REFERER', 'redirect_if_referer_not_found'))
- [Django]-Django – why is the request.POST object immutable?
- [Django]-Django Many-to-Many (m2m) Relation to same model
- [Django]-What does on_delete do on Django models?
21👍
from django.http import HttpResponseRedirect
def someview(request):
...
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
taken from: https://stackoverflow.com/a/12758859/14020019
- [Django]-Django contrib admin default admin and password
- [Django]-Row level permissions in django
- [Django]-Setting the selected value on a Django forms.ChoiceField
18👍
to redirect to the same page (e.g. an http GET) after a POST, I like…
return HttpResponseRedirect("") # from django.http import HttpResponseRedirect
it also avoids hardcoding the show:detail
route name, and is a lil’ clearer intention wise (for me at least!)
- [Django]-How to use Python type hints with Django QuerySet?
- [Django]-Django – getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}
- [Django]-PIL /JPEG Library: "decoder jpeg not available"
3👍
I am guessing you need to provide a kwarg to identify the show when you redirect, although I can’t see the code for your DetailView
I would assume the kwarg is called either pk
or possibly show
going from the convention you’ve used in AddSeason
and SubtractSeason
. Try:
redirect('show:detail', kwargs={'show': instance.pk})
EDIT: the name of the detail url is 'show-detail'
, so the scoped viewname would be 'show:show-detail'
(if it is in the show
namespace like the other urls). I still think it would need a kwarg though, try:
redirect('show:show-detail', kwargs={'show': instance.pk})
- [Django]-Convert seconds to hh:mm:ss in Python
- [Django]-How do you configure Django to send mail through Postfix?
- [Django]-Django content-type : how do I get an object?