3👍
I struggled to get the correct style for a table I was also rendering via:
{% render_table table %}
In your tables.py file you can do as follows to set attributes of the table itself (such as its’ class):
class TableView(tables.Table):
class Meta:
attrs = {'class': 'table table-striped table-hover'}
0👍
Styling a table generated by django-tables2 is explained in the documentation. You can use the default class attributes, or specify custom ones.
In order to use your custom style sheet customstyle.css
(using the classes mentioned above), you must include it into your template. django-tables2 doesn’t do that for you, but you can learn how to do that from the django tutorial part 6:
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
You have to adjust names and paths according to the location in your project.
- [Django]-Calculating and Storing Average data on a daily, weekly and monthly and yearly basis
- [Django]-How to use django-taggit similar_objects() with Class-based views
- [Django]-How can I tell if a value is a string or a list in Django templates?
Source:stackexchange.com