Customizing table style¶
CSS¶
In order to use CSS to style a table, you’ll probably want to add a
class or id attribute to the <table> element. django-tables2 has
a hook that allows arbitrary attributes to be added to the <table> tag.
>>> import django_tables2 as tables
>>>
>>> class SimpleTable(tables.Table):
... id = tables.Column()
... age = tables.Column()
...
... class Meta:
... attrs = {'class': 'mytable'}
...
>>> table = SimpleTable()
>>> # renders to something like this:
'<table class="mytable">...'