Django get_success_url() to Previous Page
Aug. 22, 2022
django
Easy way to redirect user on previous (original) page after form processing it is use HTTP_REFERER
header, here an example how it’s may be implemented in the get_success_url()
of the Django’s class based view.
class SomeEntityCreateView(CreateView):
template_name = 'template_name.html'
model = ModelName
form_class = FormName
def get_success_url(self):
return self.request.META.get('HTTP_REFERER')