I am using flask to do some user interaction. Basically, when the user clicks a button on page A or B, it goes to url C to get some data which does not have a visualization. After getting the data, I want to go back to the original page (A or B). How shall I find out where the user came from?
Another method you can use when performing redirects in Flask is the url_for() function. The way that url_for() works is instead of redirecting based on the string representation of a route, you provide the function name of the route you want to redirect to.
The url_for() function is used to build a URL to the specific function dynamically. The first argument is the name of the specified function, and then we can pass any number of keyword argument corresponding to the variable part of the URL.
I think what you need is request.referrer. There are some examples here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With