redirect from jquery in flask application

Viewed 26

I am using flask to make an application and I made a separate file for jquery (i.e in static/script/jquery.js).

I want to redirect to homepage which is in template folder, how can I do that?

I tried: window.location.href = "{{url_for ('home_page')}}"

This is not working, here is the error message.

error message

1 Answers

As clarified in the comments, you cannot expect a Jinja2 rendering transformation of a code fragment expressing a route url_for(..) when it is passed to the client as an included static page.

You need to ensure that all such transformations are in the main html document delivered to the client side using flask's render_template() function.

Related