html - How to insert a JavaScript variable into Flask url_for() function? -


i have following code in flask template:

<div id="cell1"></div> <script> var id="0014"; cell1.innerhtml = '<a href={{url_for('static',filename='+id+'".txt")}}">'+id+'</a>'; </script> 

i want link render to:

http://my_address/static/0014.txt 

but got this:

http://my_address/static/+id+.txt  

how make js variable id in flask url_for() function work?

thanks help!

try this:

cell1.innerhtml = '<a href={{url_for('static', filename='')}}' + id + '.txt>' + id + '</a>'; 

url_for() generate link this: .../static/<filename>. if use url_for('static', filename=''), generate link like: .../static/, can add text after (i.e. + id + '.txt>') .


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -