I'm using django-tables2 in my Django project and I would like to change dynamically the header of some columns according to a database query, which is done in view.py.
I know that in tables.py one can change the "verbose_name" attribute of each and every column but I would like to assign a template variable "{{ headerxy }}" for example so that it changes dynamically.
Or is there a way to change the "verbose_name" attribute in the view.py ?
Something like:
table.columns['column1'].header = some_data
Thanks
One way of doing it would be:
1) render the table with custom template
2) create html template to display your custom table columns, and only extending specific template's block, in
my_template.html
:HTH.
Here what you have to do is to pass the column name as parameter when initialising the Table class and use it within
__init__
scope of that class. For example:Table Class:
View: