Redirect in Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Redirect in Python (/thread-33153.html) |
Redirect in Python - vj78 - Apr-02-2021 Python web application: In asp, I can do a simple response.redirect('www.google.com') how to do it in PYTHON? I have a Login Page submits to .py page for database connection. After successful login check in the .py page, I would like the .py page to redirect it to success.html page. Yes, I am not using any frameworks. I have 3 different pages. 1)Login Page 2)Check.py 3)Sucess.html Login Page has a form username and password Check page connects to DB and checks if the user exists Success page In Check.py, On success login check I would like the page to redirect and go to success page. I am not sure how to? RE: Redirect in Python - SheeppOSU - Apr-03-2021 I don't quite get this question. If you're using Python to run a web application, then you're most likely using either Flask or Django (and if this is the case then please specify which). If you're not using either of those nor another library, then this question is very confusing to me. Please explain your question in more detail. RE: Redirect in Python - vj78 - Apr-03-2021 (Apr-03-2021, 01:52 AM)SheeppOSU Wrote: I don't quite get this question. If you're using Python to run a web application, then you're most likely using either Flask or Django (and if this is the case then please specify which). If you're not using either of those nor another library, then this question is very confusing to me. Please explain your question in more detail.Yes, I am not using any frameworks. I have 3 different pages. 1)Login Page 2)Check.py 3)Sucess.html Login Page has a form username and password Check page connects to DB and checks if the user exists Success page In Check.py, On success login check I would like the page to redirect to success page. I am not sure how to? RE: Redirect in Python - SheeppOSU - Apr-03-2021 Could you provide some of your code? RE: Redirect in Python - ndc85430 - Apr-03-2021 Remember that 3xx status codes are for redirects: https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections. RE: Redirect in Python - snippsat - Apr-03-2021 (Apr-02-2021, 10:41 PM)vj78 Wrote: Yes, I am not using any frameworks. I have 3 different pages. 1)Login Page 2)Check.py 3)Sucess.htmlYou should use a Framework like a simpler one like Flask to avoid doing a lot of unnecessary stuff to fit stuff together. In the older day CGI(dead now) was a thing,but after WSGI that now all Framework is build on top on. So do not use use WSGI directly as Framework like Flask, FastAPI is layer above and has done all the undelaying stuff. Could use Requests. import requests response = requests.get('http://github.com/', allow_redirects=False) print(response.status_code) # 301 redirect is a permanent redirect response.url # http://github.com, not https so redirect dest = response.headers['Location'] # https://github.com/ -- the redirect destination print(dest) But Form and redirect all of this and more is build in a light Framework like eg Flask. from flask import Flask, redirect app = Flask(__name__) @app.route('/') def page(): return redirect('http://github.com/', code=301) if __name__ == "__main__": app.run() |