【发布时间】:2015-05-11 09:20:45
【问题描述】:
我在从视图呈现的模板中有一个列表,rate_text ['', 'Disappointed', 'Not Promissing', 'OK', 'Good', 'Awesome']。我可以使用{{rate_text.index}} 访问其中的任何项目,如下所示:
{% for review in reviews %}
<div class="panel panel-info" style='border-color:#ffffff;'>
<div class="panel-heading" >
<h3 class="panel-title lead">{{review.title}}</h3>
</div>
<div class="panel-body">
<p class='text-center'>{{review.review}}</p>
<h5 class='text-right'>-{{review.username}} ( {{review.email}} ) </h5>
<h5 class='text-right'>Rating : {{rate_text.4}}</h5>
</div>
</div>
<hr>
{% endfor %}
但是,我不想在{{rate_text.index}} 中使用索引,而是使用{{review.rating}} 作为索引。有什么办法可以做到这一点??
提前致谢。
【问题讨论】:
标签: python django django-templates django-template-filters