If the success_url is determined by the model, we can customize the generic view as below.
def get_success_url(self):
return '/object/%s' % (self.object.id)
But if the success_url is irrelevant with the model, such as, we want to return to the page before we entered the form page. It can be a detail page, a list page, or anything else. Can I store the referral url in the form? Any idea is appreciated.
~Hanson
I assume that the success page will not always be the same as otherwise you could just include the url with something like
reverse()inget_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: