0

I have a flask route

@app.route('/another/<int:value>')
def another():
    return 'another'

Using javascript, I'm trying to access the url for this route using url_for within jinja2 template braces

<script>
    const v = 1;
    const sample = "{{url_for('another', value=v)}}";
</script>

doing this raises an error jinja2.exceptions.UndefinedError: 'v' is undefined. I suspect v is outside the scope of the jinja templates. Is there a way around this?

Kun.tito
  • 165
  • 1
  • 7
  • 1
    Jinja runs server-side while JavaScript runs on the client. A combination in this way is not possible because the variable does not yet exist. – Detlef Jan 01 '23 at 11:45
  • Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – β.εηοιτ.βε Jan 02 '23 at 09:14
  • @β.εηοιτ.βε yeah, it does – Kun.tito Jan 02 '23 at 13:00

0 Answers0