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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -

php - Autoloader issue not returning Class -