4

我在一个不呈现 CSS 的视图中有一个表格。我想这是一个愚蠢的错误,但我在路上找不到任何解决方案:(

风景 :

class ContactsTable(tables.Table):
    selection = tables.CheckBoxColumn(accessor="id")
    class Meta:
        model = Contact
        exclude = ("id", "civilite", "ad1", "ad2", "cp")
        sequence =("selection", "nom", "prenom", "comments", "telport", "telfixe", "email", "ville", "regime")

def ListContacts(request):
    table = ContactsTable(Contact.objects.all())
    RequestConfig(request).configure(table)

    return render(request, "contacts/contact_list.html", {'table': table})

模板:

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

对不起,我糟糕的英语和 noobie 问题。

4

1 回答 1

8

对于任何有同样问题的人,不要忘记 attrs...

class ContactsTable(tables.Table):
    class Meta:
        model = Contact
        exclude = ("id", "civilite", "ad1", "ad2", "cp")
        sequence =("selection", "nom", "prenom", "comments", "telport", "telfixe", "email", "ville", "regime")
        --> attrs = {"class": "paleblue"} <--

    selection = tables.CheckBoxColumn(accessor="id")
于 2013-09-16T08:49:22.770 回答