Django: Context not available when rendering a djang_tables2 table

I have a django_tables2 class:

class DeviceTable(tables.Table):
    class Meta:
        template_name = "main/tables/bootstrap_custom.html"

Then a base class:

class BaseClass(SingleTableMixin, LoginRequiredMixin, PermissionRequiredMixin, FilterView):
    def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
        context = super().get_context_data(**kwargs)
        context["foo_base"] = "bar_base"
        return context

And a view class:

class ViewClass(BaseClass):
    table_class = DeviceTable

    def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
        context = super().get_context_data(**kwargs)
        context["foo_view"] = "bar_view"
        return context

When rendering the "bootstrap_custom.html", the context doesn't contain the expected information. Neither "{{ foo_base }}" nor "{{ foo_view }}" are available in the context. Any idea?

Just got it! I have to use "{{ table.context.foo_base }}".

Back to Top