2๐
โ
I assume that the success page will not always be the same as otherwise you could just include the url with something like reverse()
in get_success_url
.
For a dynamic redirect you could either, like you suggested add the url in a hidden input to the form or in the querystring of the url the form is posted to (eg. /myurl?next=/redirect-url/
). Then you could do in your view class something like:
# url is in the form in a hidden input 'next'
def get_success_url(self):
return request.POST['next']
# url is in the query string ?next=xxxx
def get_success_url(self):
return request.GET['next']
๐คBernhard Vallant
Source:stackexchange.com