Django tables2无法正确呈现

时间:2016-08-24 15:35:08

标签: django django-tables2

我正在关注https://django-tables2.readthedocs.io/en/latest/pages/table-data.html#querysets

上的示例

上面显示的示例对我来说无法正常工作。请参阅下面的代码。表格显示但未正确呈现。

表示,如果我使用对象集合,而不是使用PersonsTable()

PersonsTable()来自上面的页面。

我希望能够使用PersonsTable()的字段来过滤显示的列,并从django-tables2获得漂亮的格式...

提前致谢。

我的代码:

def person_list(request):
    #table = PersonsTable(Person.objects.all())  # this is from example, table is rendered plainly w/o any formatting present or up/down arrows
    table = Person.objects.all()                 # rendering works

    return render(request, 'person_list.html', {'table': table})

模板:

{% load render_table from django_tables2 %}
<!doctype html>
<html>
   <head>
    <link rel="stylesheet" href="/static/django_tables2/themes/paleblue/css/screen.css" />
   </head>
   <body>
    {% render_table table %}
   </body>
</html>

1 个答案:

答案 0 :(得分:2)

修改我的PersonsTable类以包含&#39; attr ...&#39;后,表现在呈现。

class PersonsTable(django_tables2.Table):

    class Meta: 
        attrs = {"class": "paleblue"}   # this fixed table rendering
        model = Person
相关问题