我希望这个问题相对容易些,但由于我是Django的新手,所以我在努力。在
我有一个查询集,它是给一个模板的。基本上我想创建一个足球桌。但总的来说我想理解这个概念。在
因此,对于teams查询集中的每个团队,数据应该分别填充在5个相应的列中。目前,我通过在每个列中添加一个for循环来解决这个问题。不过,我觉得这很难看。此外,我想编辑前三个循环的id。在
所以我要寻找的是:一种围绕div设置for循环的可能性,但不在每个循环中创建div。在
比如:
{%for team in teams %}
<div id="position">team.position</div>
<div id="name">team.name</div>
...
{% endfor %}
除了添加以下内容:
^{pr2}$这里最聪明的方法是向类添加变量,意思是class={xyz}}?在
模板看起来像这样。在
<div class="row">
<div class="col-md-2" id="position">{% for tea in teams %}{{tea.league_position}}</br>{% endfor %}</div>
<div class="col-md-4" id="name">{% for tea in teams %}{{tea.team_name}}</br>{% endfor %}</div>
<div class="col-md-2" id="points">{% for tea in teams %}{{tea.league_points}}</br>{% endfor %}</div>
<div class="col-md-2" id="goals">{% for tea in teams %}{{tea.goals_shot}}</br>{% endfor %}</div>
<div class="col-md-2" id="received">{% for tea in teams %}{{tea.goals_received}}</br>{% endfor %}</div>
</div>
谢谢你的帮助!!!!! 西蒙
如果您不想包括div,那么唯一可能的方法就是执行ajax请求来分别填充列。。。在
以下是未经测试的(可能是错误的),但它应该给我一个想法的意思
你在用div做桌子。用表格代替。在
相关问题 更多 >
编程相关推荐