Does anyone know if flask redirect is able to open a link / URL in a new tab?
@app.route('/test')
def my_page():
return redirect('http://mylink.com', 301)
I would like if the mylink website opened in a new tab, any insights?
Does anyone know if flask redirect is able to open a link / URL in a new tab?
@app.route('/test')
def my_page():
return redirect('http://mylink.com', 301)
I would like if the mylink website opened in a new tab, any insights?
As far as I know that would not be a flask issue. You have to open a new tab within your html code or with Javascript.
example:
<a href="http://mylink.com" target="_blank">Link</a>
The server has no power over what the browser does in this case.
You could also use Python's webbrowser module to open a page, if you'd like to avoid getting into the HTML
import webbrowser
@app.route('/test')
def my_page():
return webbrowser.open_new_tab('http://mylink.com')
A slight adjustment to @garettmd that fixes @John Jiang's issue:
import webbrowser
from flask import Flask, redirect, url_for
@app.route("/test/")
def test():
webbrowser.open("https://google.com")
return redirect(url_for("index"))
This way we get to return a redirect (which we should probably do anyway) and we also get our new tab without "The view function did not return a valid response" error.