如何在CSS选择器中使用Django模板语法?

2024-05-15 16:53:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Django很陌生,我一直在想这个问题

是否有任何方法可以将模板语法放入CSS选择器中,如下所示:

{% for i in list %}
    <!-- I know for a fact that 'list' has data in it -->
    <div id='div{{ forloop.counter }}'>test{{ forloop.counter }}</div>
    <style>
        #div{{ forloop.counter }} {
            color: blue;
        }
    </style>
{% endfor %}

并让它生成以下代码:

<div id='div1'>test1</div> <style> #div1 { color: blue; } </style> <div id='div2'>test2</div> <style> #div2 { color: blue; } </style> <div id='div3'>test3</div> <style> #div3 { color: blue; } </style>

我尝试过这个,但是<style>标记完全不起作用

有没有办法做到这一点,如果有,如何做到


Tags: djangoindividforstylecounterblue