Search code examples
pythondjangodjango-tables2

Is it possible to custom django-tables2 template for a specific page in this case?


I'm using django-tables2 to render my data in tables in the template.. everything is rendered fine with pagination..

The Designer of our company wants to change the Display of data into blocks instead of simple table. the following picture may explain more.

enter image description here

I Want to ask if I can use Django tables2 in this case ..since I don't want to loose the pagination

Is it possible to custom the django_tables2/table.html file to only fit this case (because I'm using django-tables2 in many other pages in the project)?

Any other ideas may be helpful.

Thanks in advance :)


Solution

  • Yes, you can create a custom template (based on django_tables2/table.html) and set a specific table's template Meta attribute to its path:

    import django_tables2 as tables
    
    class Table(tables.Table):
        # columns
    
        class Meta:
            template = 'table-blocks.html'
    

    or use the template argument to the Table constructor:

    table = Table(queryset, template='table-blocks.html')
    

    or use the second argument of the {% render_table %} templatetag:

    {% load django_tables2 %}
    {% render_table queryset 'table-blocks.html' %}