Reputation: 21
I am writing a simplest possible example of django-table2
it fails with
Error during template rendering
In template /myproject/app/templates/test_table.html, error at line 2
Any clue what's wrong here. just following document.
context
1 {% load render_table from django_tables2 %}
2 {% render_table table %}
3
class TestTable1(models.Model):
col1 = models.CharField(max_length=1, primary_key=True)
col2 = models.FloatField(blank=True, null=True)
class Meta:
managed = False
db_table = 'test_table1'
class TestTable1Tbl(tables.Table):
class Meta:
model = TestTable1
attrs = {"class":"paleblue"}
def test_table(request):
table = TestTable1Tbl(TestTable1.objects.all())
RequestConfig(request).configure(table)
return render(request,"test_table.html",{'table':table})
$ more test_table.html
{% load render_table from django_tables2 %}
{% render_table table %}
During handling of the above exception (could not convert string to float: 'table'), another exception occurred:
return template.render(context.flatten())
Upvotes: 1
Views: 1837
Reputation: 1
I had this same problem, but the answer above initially puzzled me.
The table.html file seems to be the default template that render table expects to find. I found that specifically setting the template_name and adding the django_tables2
to the file path resolved the issue without copying the file from the django2 source.
So applying to the example above ( I also choose boostrap.html
instead of table.html
)
class TestTable1Tbl(tables.Table):
class Meta:
model = TestTable1
attrs = {"class":"paleblue"}
template_name = 'django_tables2/bootstrap.html'
Upvotes: 0
Reputation: 21
The problem was with table.html file. the issue is resolved after copied under /templates/django_tables/, Thank you.
Upvotes: 1