Im attempting to implement a dynamic url dispatcher as follows:
"{% url 'url_name' 'variable' %}"
where variable
is generated dynamically in my javascript.
My goal is to redirect to another page when the value of a <select>
element changes.
$(document).ready(function() {
$('#select').change(function() {
var id = $('#select').val();
window.location.replace("{% url 'url_name' 'id' %}");
});
});
I am unable to achieve this using simple string concatenation like so:
"{% url 'url_name' '" + id + "' %}"
because it results in an error stating Reverse for 'url_name' with arguments '('" + id + "',)' not found.
The <select>
element is populated with backend data:
<select id="select">
{% for item in list %}
<option value="{{item.id}}">{{item.name}}</option>
{% endfor %}
</select>
I am struggling to find the correct syntax for accomplishing this task.