首页 > 解决方案 > 使用 django-tables2 呈现带有字典列表的表行时遇到问题

问题描述

我在通过使用 django-tables2 传递字典列表来呈现表格行时遇到问题。

views.py
========

list_of_dict = [{"File Path": 'path1', "Age": 500, "No of files": 90},
                {"File Path": 'path2', "Age": 400, "No of files": 25}]
nt = Small_table(list_of_dict)

RequestConfig(request).configure(nt)
return render(request, "collectionsec.html", {"small": nt})

tables.py
=========

import django_tables2 as tables

class Small_table (tables.Table):
    name = tables.Column()
    age = tables.Column()
    nof = tables.Column()

    class meta:
        attrs = {'class': 'paleblue'}
        attrs = {'class': 'table table-responsive', 'width': '100%'}

collectionsec.html
==================

{% load django_tables2 %}
{% render_table small %}

这是输出的样子:

Name Age Nof
—   —   —
—   —   —

有人可以帮我吗?

提前致谢 :)

标签: pythondjangodjango-tables2

解决方案


找出问题所在!内部类应该命名为“元”而不是我的“元”


推荐阅读