[Fixed]-"next" is not redirecting to expected position

1👍

I’m not sure it how it even manages to get to the account page since you’re using the render tag as a mixture of render and redirect.

return render(request, '/add_money/')

You should return a redirect response back to the next url instead

return HttpResponseRedirect(request.GET['next'])

Also, you’re passing the next to the login template, not the url

if not request.user.is_authenticated():
        return render(request, 'registration/login.html', {"next": '/add_money/'})

you should redirect to the login page here as well with next as a get parameter

    return  HttpResponseRedirect('/login/?next={}'.format('/add_money/')

You should also look into using the provided url reversing methods instead of hard coding urls


You also should remove the whole if next in the template and just let the login action be the default for the page

{% if next %}
    <form action="/login/?next={{next}}" method="post">
        <input type="hidden" name="next" value={{ next }}>
{%else%}
    <form action="/login/" method="post" >
{% endif %}

should be

<form method="post" >

Leave a comment