Well, I think your problem is not in django-tables2 version. Here I think that when you pass a variable from a view to a template, you pass a string instead of a queryset / table class object. For a working example:
Table class:
class SomeTable(tables.Table): class Meta: model= SomeModel attrs = {"class": "paleblue"}
View Class:
class SomeTableView(SingleTableView): model = SomeModel template_name = 'test.html' table_class = SomeTable
Template:
{% load render_table from django_tables2 %} {% render_table table %}
Or you can directly send a query to display the table as follows:
class SomeView(TemplateView): def get(self, request, *args, **kwargs): data = SomeModel.objects.all() context = self.get_context_data(**kwargs) context['table'] = data return self.render_to_response(context)
and do it like this:
{% load render_table from django_tables2 %} {% render_table table %}
source share