将静态路径传递给包含的模板

是否可以将静态路径作为变量传递给包含的模板?


我需要在我的页面上重复包含一个模板,但它总是带有不同的徽标。


例如:


    {% with img={% static 'img/dashboards/belgium_flag.svg' %} %}

        {% include 'dashboards/charts/country_block.html' %}

    {% endwith %}


    {% with img={% static 'img/dashboards/netherlands_flag.svg' %} %}

        {% include 'dashboards/charts/country_block.html' %}

    {% endwith %}

这不行..


除了创建一个模型来支持每个国家/地区实例的图像属性之外,还有其他解决方法吗?


莫回无
浏览 81回答 1
1回答

开满天机

您可以使用一个{% … as … %}子句来做到这一点:{% static 'img/dashboards/belgium_flag.svg' as img %}{% include 'dashboards/charts/country_block.html' %}{% static 'img/dashboards/netherlands_flag.svg' as img %}{% include 'dashboards/charts/country_block.html' %}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python