django templates - 在模板之间传递变量

use*_*607 3 html django django-templates

我有一个包含弹出页面的模板。我循环遍历从视图中获取的列表中的所有值,并希望在弹出窗口中包含列表中每个元素的信息。

第1页.html:

{% include "popup.html" %}
...
{% for element in someList %}
    <div class="col s3 some-button"><a onclick="$(showPopup('popup'));">More Info</a></div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

showPopup 是一个 Javascript 函数,用于显示弹出窗口。

在 popup.html 中,我引用了element上面的 for 循环:

弹出窗口.html

...
{{ element }} 
...
Run Code Online (Sandbox Code Playgroud)

但是 popup.html 模板似乎无法element从 for 循环中找到 ,因为没有显示任何内容。有没有办法让 popup.html 能够引用element

use*_*607 5

我发现使用它可以达到我的目的:

第1页.html:

...
{% for element in someList %}
    {% include "popup.html" with element=element %}
    <div class="col s3 some-button"><a onclick="$(showPopup('popup'));">More Info</a></div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)