简体   繁体   中英

Window.location.href with url_for() in flask?

I have an html page with Javascript Attached to it. I have a Button. When it's clicked It redirects to another page using window.location.href And since iam using flask I Used url_for() window.location.href ="{{ url_for('routeName')}}"

But it's Not Working Flask Says That The Requested url is not found. How can I Make url_for work with window.location.href?

You can use

<a href="{{ url_for('routeName') }}?next={{ request.path }}">Sign in</a>

request.path is getting the path of the current page. You don't even need the any js you can add it to the button's element. More information . I did upload an answer because I wasn't sure if this is exactly what you need since you didn't share any code with us.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM