~ / blog / development / django-get_success_url-to-previous-page
django 2022-08-22·1 min read

Django get_success_url() to Previous Page

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.

python
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')