How to redirect an external domain to Flask?

I need to redirect back to an external url after completing an action in my jar application. The code is as follows:

if form.next.data is not None:
    return redirect(form.next.data)

where form.next.datamay be the absolute URL for an external domain such as "www.google.com". However, when passing the next value as an external URL, this redirect instead redirects to http://mysitename/www.google.comand with a 404 error.

How do I indicate that a redirect belongs to an external domain and stop the checkbox by adding it to my domain root?

+4
source share
2 answers

, http:// https:// "www.google.com". Flask URL- . , 404, localhost: 5000/www.google.com.

@app.route('/test')
def test():
    return redirect("www.google.com")

http://, .

@app.route('/test')
def test():
    return redirect("http://www.google.com")
+11

URL- , "http://" .

s = form.next.data
if s is not None:
    if s.find("http://") != 0 and s.find("https://") != 0:
        s = "http://" + s
    return redirect(s)
+2

Source: https://habr.com/ru/post/1538419/


All Articles