Search code examples
djangodjango-templatesdjango-appsdjango-template-filterstemplatetags

Rename/add prefix to third party app template tags?


Is it possible to add prefix or rename third party app template tags?

Explanation:

We use django_tables2 in our project. For performance purposes, we decided to migrate from django_tables2 to django_datatable (https://github.com/shymonk/django-datatable).

We want to use django_tables2 for a couple of tables and migrate rest of them to django_datatable.

The problem is that both django_tables2 and django_datatable uses the same template tag {% render_table table %}. And maybe there will be more problems when we go deeper.


Solution

  • You can reregister the tag with a different name:

    from table.templatetags.table_tags import register, render_table
    
    register.tag('datatable_render_table', render_table)
    

    You should put this somewhere it is executed during startup, for example in AppConfig.ready().