【发布时间】:2021-07-09 13:26:54
【问题描述】:
我正在尝试使用动态 url 调度程序,例如:
"{% url 'url_name' 'variable' %}" variable 在我的 javascript 中动态设置。
我想要做的基本上是在 <select> 值更改时重定向到不同的页面。
$(document).ready(function() {
$('#select').change(function() {
var id = $('#select').val();
window.location.replace("{% url 'url_name' 'id' %}");
});
});
我不能像这样使用简单的字符串 concat 来做到这一点:
"{% url 'url_name' '" + id + "' %}" 因为它返回此错误 Reverse for 'url_name' with arguments '('" + id + "',)' not found.
选择本身正在填充后端数据:
<select id="select">
{% for item in list %}
<option value="{{item.id}}">{{item.name}}</option>
{% endfor %}
</select>
我不知道这是什么语法。
【问题讨论】:
标签: javascript django django-templates