【发布时间】:2011-07-29 13:39:03
【问题描述】:
可能重复:
how to pass the variable from included template to the template where it is included?
main.html
{% extends "new-base.html" %}
{% block side-bar %}
<div id="foo1">
{% for foo in foo_list %}
{{ foo_id }} // ???
{% ifequal foo.id foo_id %}
<li id="my-id_{{ foo.id }}" class="select"><a href="#.">
{% else %}
<li id="my-id_{{ foo.id }}" class="no-select"><a href="#.">
{% endifequal %}
{% endif %}
{% endfor %}
</ul>
</div>
{% endblock side-bar %}
{% block content %}
<div class="content" id="main-content">
{% include "template/part.html" %}
</div>
{% endblock content %}
part.html
这个 html 被包含在 main.html
views.py
if request.is_ajax():
t = get_template('part.html')
html = t.render(Context({'foo_id': foo_id}))
return HttpResponse(html)
作为响应,它将发送part.html 但我正在使用foo_id 将它发送到main.html。 main.html
包括part.html 但{{ foo_id }} 中的main.html 并没有给我任何价值。我用??? 表示了位置但是当我渲染整个模板时(不添加html
div 中的数据)然后它给出正确的数据。
jquery
$.ajax({
type:'GET',
cache: 'false',
url:"/foobar/",
success:function(data) {
$('#main-content').html(data);
}
});
【问题讨论】:
-
此处未回答问题的完全相同的副本:stackoverflow.com/questions/5541312/…
-
抱歉,我需要更准确地表述问题
-
您可以编辑您的问题以使其更清楚,而不是创建一个新帐户并重新发布问题。