3
I am trying to export a table with Django-Tables2, I have done the following so far.
Tables py.
class ClienteTable(ColumnShiftTable):
class Meta:
model = Cliente
sequence = ('id', 'nome_razao_social', 'cpf', 'cnpj', 'sit_fiscal')
template_name = 'django_tables2/bootstrap.html'
py views.
class RelatorioClientesView(ExportMixin, CustomListView):
template_name = 'relatorios/clientes/geral.html'
model = Cliente
table_class = ClienteTable
context_object_name = 'all_clientes'
permission_codename = 'view_clientes'
def get_context_data(self, **kwargs):
context = super(RelatorioClientesView,
self).get_context_data(**kwargs)
table = ClienteTable(Cliente.objects.all())
table.paginate(page=self.request.GET.get('page', 1), per_page=15)
context['table'] = table
RequestConfig(self.request).configure(table) #ordena
export_format = self.request.GET.get('_export', None)
if TableExport.is_valid_format(export_format):
exporter = TableExport(export_format, table)
return exporter.response('table.{}'.format(export_format))
return context
html template.
<div class="tabela" style="overflow-x: auto; white-space: nowrap;">
{% load render_table from django_tables2 %}
{% render_table table %}
{% export_url "csv" %}
</div>
But I get that mistake Invalid block tag on line 56: 'export_url', expected 'endblock'. Did you forget to register or load this tag?
What I’m doing wrong?
you’re following this one tutorial?
– Davi Wesley
Yes, I am following
– Rafael