相关疑难解决方法(0)

使用模板标记在html模板中求和

我想在HTML中求和,但模板标签返回0,

View.py

def gen_Report(request):

### query returns below output 
list=[{'total': 1744, 'user': u'x'}, {'total': 13, 'user': u'y'}, {'total': 126, 'user': u'z'}, {'total': 46, 'user': u'm'}, {'total': 4, 'user': u'n'}, {'total': 8, 'user': u'o'},  {'total': 3, 'user': u'p'}]

return render_to_response('user.html', locals(),
                            context_instance = RequestContext(request))
Run Code Online (Sandbox Code Playgroud)

模板:

user.html

  {% load temptags %}

 <table id="myTable" class="tablesorter">
    <thead>
    <tr>

    <th>S.No</th>
    <th>role</th>
    <th>Count</th>

    </tr>
    </thead>
    {% for fetch in list %}

    <tr>
    <td>{{forloop.counter}}</td>
    <td>{{fetch.user}}</td>
    <td>{{fetch.total}}</td>



    {% endfor %}
    <td>{{ list.total|running_total}}</td>
    <tr>

    </table>
Run Code Online (Sandbox Code Playgroud)

模板标签:

from django.template import …
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-template-filters

2
推荐指数
1
解决办法
8179
查看次数