【发布时间】:2016-05-30 03:14:55
【问题描述】:
我有一个 django 模板部分
{% for l in items%}
<td style="text-align: center"
id="{{m.id}}_{{m.set|slice:':7' }}_{{m.kidu}}_{{l}}">
</td>
{% endfor %}
和下面的JS部分:
<script>
$(document).ready(function() {
{% for a in all_results %}
$('#{{a.id}}_{{a.set|slice:":7"}}_{{ a.kidu}}_{{ a.adi|slice:":2" }}').html('{{ a.id }}');
$('#{{a.id}}_{{a.set|slice:":7"}}_{{ a.kidu}}_{{ a.adi|slice:":2" }}').addClass('{{ a.state__name.split|join:"_" }}');
{% endfor %}
});
</script>
我正在尝试在我的模板中将 id 作为 href 链接传递,这样一旦用户单击该链接,他就会重定向到该特定记录详细信息视图。
我尝试如下:
<script>
$(document).ready(function() {
{% for a in all_results %}
$('#{{a.id}}_{{a.set|slice:":7"}}_{{ a.kidu}}_{{ a.adi|slice:":2" }}').html('{{ href="{% url 'req_detail_view' a.id %}"}}');
$('#{{a.id}}_{{a.set|slice:":7"}}_{{ a.kidu}}_{{ a.adi|slice:":2" }}').addClass('{{ a.state__name.split|join:"_" }}');
{% endfor %}
});
</script>
但是我得到Could not parse the remainder: '="{% url 'req_detail_view' a.id %}"' from 'href="{% url 'req_detail_view' a.id %}"' 任何想法家伙?提前致谢
【问题讨论】:
-
.html('{{ href="{% url 'req_detail_view' a.id %}"}}');应该做什么? -
将带有我的 id 的 url 链接传递给我的模板(td 单元格)
标签: javascript jquery python html django