python - 如何在html中使用客户过滤器? django(带数字的循环)

标签 python html django for-loop

这是我第一次使用自定义过滤器。对不起,如果它看起来太新手..

所以我正在使用这个过滤器: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/

相关文章:

python - 无法保存matplotlib.figure图,canvas为None

python - Django 调试帮助

python - 3D 数据的最佳数据结构?

javascript - 防止使用 select2 加载数据,直到满足 minlength

python - django中的可选获取参数?

python - 如何通过点符号访问数据

html - HTML div 元素中的倒序

javascript - Firefox 和 Chrome 中的字体高度不同

javascript - jQuery 多个按钮单击时显示和隐藏元素

python - Django:设置电子邮件