Python Forum
Python redirect users to another url after form post
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python redirect users to another url after form post
#1
I am Not using django or flask. How to redirect to outside URL. Such as google com or /index.html This code does not work.
return { Location : "/thank-you.html" }

I want the equivalent of

return HttpResponseRedirect('/thanks/') #Redirect after POST

I can't use javascript for this. The script needs to run completely. As of right now users are sent to the python.script.url and thats all. I need them to go to a different one.
Reply
#2
Is there a restriction to use Flask/Django?

You can use Flask in a very simple way to do this:

from flask import Flask, redirect app = Flask(__name__) @app.route("/index.html") @app.route("/") def go_to_external_url(): return redirect('http://google.com') if __name__ == "__main__": app.run(host='0.0.0.0', port=4000)
Reply
#3
I am not using either one. However, can you cut out the redirect and flask requirements to do the redirects. That sounds like the best idea to me.
Reply
#4
How are you serving the HTTP Form?
Reply
#5
No information will go to the redirect. I simply want the user to go to the Thank you page or a URL after the script has ran through or when it has completed.

I tried Javascript and ajax. and that was a failure. I do not have the knowledge to do this. The form is a sign up form and it can take several seconds for everything to load and the python script to be done. If I could do something that salesforce.com uses. The cloud when you sign up. That would be the preferred method. THis is more of a temporary thing till I can pay someone.
Reply
#6
Look if this is what you want...

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Redirect Test</title> </head> <body> <form action="/" method="POST"> First name:<br> <input type="text" name="firstname"><br> Last name:<br> <input type="text" name="lastname"> <br> <input type="submit" value="Submit" onclick="redirect()"> </form> <script> var redirect = function() { setTimeout(function(){ window.location.href = 'http://www.google.com/'; }, 1); }; </script> </body> </html>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  redirect STDIO in the Python code Skaperen 6 4,083 Jul-05-2023, 12:23 AM
Last Post: Skaperen
  Start Putty into Python Form Schlazen 5 11,157 Dec-13-2022, 06:28 AM
Last Post: divya130
  Error creating database with python and form? shams 3 4,016 Aug-02-2021, 02:00 PM
Last Post: deanhystad
  Error using mariadb select query with form in python? shams 2 3,432 Jul-29-2021, 12:30 PM
Last Post: shams
  stderr redirect to file fmr300 2 6,567 Apr-03-2021, 01:31 AM
Last Post: fmr300
  Cannot redirect print to a file tester_V 3 3,925 Sep-11-2020, 12:21 AM
Last Post: tester_V
  html, python, a simple form test 1 3,036 Aug-09-2020, 01:59 PM
Last Post: snippsat
  redirect url_for passing arguments with the url Leon79 1 2,755 Jul-09-2020, 05:20 PM
Last Post: Leon79
  How to make Python 3.7.6 accessible to users Doguhan 4 4,702 May-19-2020, 05:36 PM
Last Post: snippsat
  Redirect to __stdout__ fails in IDLE shell Pavel_47 1 3,009 Apr-13-2020, 05:13 PM
Last Post: deanhystad

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.