When i do this, it work:
return redirect('/admin-login')
But when I try to pass a http code in parameter, the redirection dont work and I get to this page:`
return redirect('/admin-login', code=401)
Redirecting...
You should be redirected automatically to target URL: /admin-login. If not click the link.
How do I fix this? Thanks
The message is actually there in both cases. Flask uses the Location header field to trigger a redirect. So when your browser sees that it skips displaying the content and immediately redirects.
The reason it doesn't work for code=401, is because 401 Unauthorized is a client error. This results in the browser ignoring the redirect (at least with Chrome).
The Flask documentation for flask.redirect mentions the following:
Supported codes are 301, 302, 303, 305, and 307.
It doesn't specifically mention why they are the only supported ones. But the best assumption is because browsers generally shouldn't redirect if it's not a 3XX status code (Redirection).
The solution is thus to use one of the supported status codes.
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