I’m using Django but being crazy and submitting forms with Javascript and stuff.
I have a form that has an action that’s only there because I couldn’t get it to process the data I wanted correctly (that is, I’m using the action URL to redirect to two different parts of a view that each do what I want). It’s working great, except after using the forms I see the URL www.example.com/formone and www.example.com/formtwo after pressing each. Due to the way it’s setup it looks just like www.example.com, except for the URL. Also if you reload the page without the POST data, using the same URL, it fails, because I only process post data from those URLs.
Is there a way to redirect at the end of the view?
For example, something like:
def formone(request):
...
...
return render(request, 'example.html', 'www.example.com', {
'formone': form, 'formtwo': voteform, 'items': items
})
where www.example.com is the redirect URL, would be desirable. I can probably do this in Javascript on the actual page, but that seems even more sketchy.
Use the redirect shortcut at the end of your view.