[Fixed]-How can I get the path of form, before it produced in view, Django

1👍

You’ll need to add an additional field to your form to let your view know where to redirect to. The simplest way to do this is to add a hidden input to your form:

<form action="/some/url/" method="post">
    ...
    <input type="hidden" name="next" value="{{ request.path }}">
</form>

The value of request.path is the path of the page before the user submits the form.

In your view, you can use the parameter next to redirect the user back to the page they came from.

def subscribe(request):
    ...
    next = request.POST.get('next', '/some/default/url/here/')
    return redirect(next)

Leave a comment