[Answer]-Django dynamic template link dictonary to object fields

1👍

You are trying to re-implmenet an already solved problem. Please use django-tables2 to render tables in django: https://github.com/bradleyayers/django-tables2

Update: To answer OP’s comment on how to remove or edit the pagination footer:

If you do not want to have pagination to your table then just configure your table passing paginate=None to your RequestConfig like this:

table = TestTable(Test.objects.all())
RequestConfig(request, paginate=None).configure(table)
return render(request, 'test.html', {'table': table})

If you want to edit the footer yourself then you have to provide a new table rendering template. To do this, you just need to copy the contents of table.html from here https://github.com/bradleyayers/django-tables2/blob/master/django_tables2/templates/django_tables2/table.html to your templates directory. You can then modify this file to your requirements, for instance the pagination section is between {% if table.page %} and the {% endif %} at the end of the file.

Now, after you’ve created your custom table template you need render your table using this template. If you named your template as mytable.html then just use the following syntax from within your normal templates:

{% render_table mytable "mytable.html" %}

Leave a comment