这是我第一次使用自定义过滤器。对不起,如果它看起来太新手..
所以我正在使用这个过滤器:https://djangosnippets.org/snippets/779/ 在 html 中循环访问一个数字。
--项目 --我的应用 --模板标签 --otherfilter.py --helper.py
在 helper.py 中,我有与链接中完全相同的代码。 在 html 中我有:
<div class="es-carousel">
<ul>
{% load helper %}
{% measurement.set.total | num_rangenum_range %}
<li><a href="#"><img src="{{ STATIC_URL }}images-gallery/thumbs/{{counter}}.jpg" data-large="{{ STATIC_URL }}images-gallery/2.jpg" alt="image02" data-description="A plaintful story from a sistering vale" /></a></li>
<li><a href="#"><img src="{{ STATIC_URL }}images-gallery/thumbs/{{counter}}.jpg" data-large="{{ STATIC_URL }}images-gallery/3.jpg" alt="image03" data-description="A plaintful story from a sistering vale" /></a></li>
<li><a href="#"><img src="{{ STATIC_URL }}images-gallery/thumbs/4.jpg" data-large="{{ STATIC_URL }}images-gallery/4.jpg" alt="image04" data-description="My spirits to attend this double voice accorded" /></a></li>
<li><a href="#"><img src="{{ STATIC_URL }}images-gallery/thumbs/5.jpg" data-large="images/5.jpg" alt="image05" data-description="And down I laid to list the sad-tuned tale" /></a></li>
<li><a href="#"><img src="{{ STATIC_URL }}images-gallery/thumbs/6.jpg" data-large="images/6.jpg" alt="image06" data-description="Ere long espied a fickle maid full pale" /></a></li>
</ul>
</div>
measurement.set.total 是我从我的模型中得到的一个数字。 也请帮助我想在我的文件目录中访问的计数器。
最佳答案
语法在网页中提供。它曾经不起作用,因为我在模板标签中输入了愚蠢的错字。
{% load helper %}
{% num_range 5 as some_range %}
{% for i in some_range %}
{{ i }}: Something I want to repeat\n
{% endfor %}
关于python - 如何在html中使用客户过滤器? django(带数字的循环),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38252975/