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
Post a Comment