Hossein Rashno
Hossein Rashno

Reputation: 3469

Redirect to external url with parameters in django

I want when a user do something in my view then i redirect him to another website with some parameters as POST method Like when you submit a form. I think its may be something like this:

return HttpResponseRedirect("url","parameters")

How can i do that?

Upvotes: 1

Views: 3272

Answers (1)

catavaran
catavaran

Reputation: 45555

You can't redirect with a POST method. The only solution for this is to show intermediate html with a form and submit this form on window.load event:

return render(request, 'my_form.html', {'param1': 'Parameter 1',
                                        'param2': 'Parameter 2'})

And my_form.html will look like:

<html>
    <body onload="document.my_form.submit()">
        <form action="http://external_url" name="my_form" method="POST">
            <input type="hidden" name="param1" value="{{ param1 }}" />
            <input type="hidden" name="param2" value="{{ param2 }}" />
        </form>
    </body>
</html>

Upvotes: 4

Related Questions