I have my Flask application running on domain.com/test/
. In my code, I'd like a redirect to return a user to domain.com/test/login if they hit any URL in the application (route handler or not) and are not logged in.
If I do redirect("/abc")
, it sends them to domain.com/abc
. If I do redirect("abc")
, and they come from a route, such as domain.com/test/bla/
, it sends them to domain.com/test/bla/abc
.
I would just like the redirect to send them to [url-flask-app-is-running-on]/[the-redirect-path-segment]
On another note, can I give redirect
an endpoint instead of a string path?
There are two ways:
you can use return redirect('domain.com/test/login')
which is a full path.
if your code is like:
@app.route('/test/login')
def login_form()
pass # Login form
then you can use return redirect(flask.url_for('login_form')
.