最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Django app template - variable to add attributes together - Stack Overflow

programmeradmin0浏览0评论

In the html template of my Django app, I am trying to have a "total" variable that would sum attributes together (using the {% with %} tag), but the result displayed on the webpage is always 0 and I can't figure out why.

Here is my HTML code:

    <table id="managerTable" class="display compact" width="100%">
        {% for manager in manager_list %}
            <thead>
                <tr>
                    <th><strong>{{manager}}</strong></th>
                    <th>Proj1</th>
                </tr>
            </thead>

            <tbody>
                {% with total=0 %}
                    {% for player in player_list %}
                        <tr>
                            {% if player.owner == manager %}
                                <td>{{player.web_name}}</td>
                                <td>{{player.exp_x_score_1}}</td>
                                {% with total=total|add:player.exp_x_score_1 %}
                                {% endwith %}
                            {% endif %}
                        </tr>
                    {% endfor %}

                    <tr>
                        <td></td>
                        <td></td>
                        <td><strong>TOTAL</strong></td>
                        <td><strong>{{total}}</strong></td>
                    </tr>
                {% endwith %}
            </tbody>

        {% endfor %}
    </table>

The attribute player.exp_score_1 is well displayed and non 0.

发布评论

评论列表(0)

  1. 暂无评论