Reputation: 6470
How do I assign an argument value to a Django template tag, using JavaScript?
{% url path.to.some_view arg=v %}
This doesn't work:
<script>
var v = 5;
</script>
{% url path.to.some_view arg=v %}
Upvotes: 2
Views: 797
Reputation: 56
This should work:
<script>
var v = 5;
var url = '{% url path.to.some_view 999 %}'.replace (999, v);
</script>
Upvotes: 2
Reputation: 1328
You could do something like: < A HREF="{% reverse path.to.some_view %}&arg=" + document.v">Some_view< /A>
Upvotes: 0
Reputation: 1148
You can't.
By the time the browser has the HTML, and the javascript is being executed the django template has already been compiled serverside and the resulting html is being displayed by your browser.
Upvotes: 6