Error Using django-tables2 - expected table or set of queries, not 'str'

I am trying to create multiple tables for my application using django-tables2 and am encountering some difficulties. I am using Python 2.7 and Django 1.7. I am following a tutorial and I am having problems.

I got to the point that I need to create a Table class for customization. However, whenever I do this, I get the following error:

The expected table or set of queries, not 'str'.

After some research, it looks like I'm using an old version of django-tables2. However, I only installed it yesterday with pip install django-tables2 and updated it half an hour ago. Any idea how I can get django-tables2 to work properly?

EDIT - Problem resolved. I used {% render_table people %} instead of {% render_table table %}

+9
source share
4 answers

I also ran into this problem. The first thing you need to do is check your updates.
sudo pip install django-tables2 --upgrade
sudo pip install django-tables2-reports --upgrade
Modernization also did not help my problem.
If you have already updated their version. You should check your implementation. If you use Class Based View, and you are sure that you are implementing a view, template, table. You should probably forget the urls. Therefore, the URLs should look like this.

 /* I give the example with respect to other post*/ urls.py /*Same dic with table.py,models..etc*/ from .views import SomeTableView urlpatterns = patterns('', url(r"^$", SomeTableView.as_view(), name="index"), ) 

If this is not your site’s index, you should probably change r "^ $" and name = "index"

+6
source

Well, I think your problem is not in django-tables2 version. Here I think that when you pass a variable from a view to a template, you pass a string instead of a queryset / table class object. For a working example:

Table class:

 class SomeTable(tables.Table): class Meta: model= SomeModel attrs = {"class": "paleblue"} 

View Class:

 class SomeTableView(SingleTableView): model = SomeModel template_name = 'test.html' table_class = SomeTable 

Template:

  {% load render_table from django_tables2 %} {% render_table table %} <!-- Here I am passing table class --> 

Or you can directly send a query to display the table as follows:

 class SomeView(TemplateView): def get(self, request, *args, **kwargs): data = SomeModel.objects.all() context = self.get_context_data(**kwargs) context['table'] = data return self.render_to_response(context) 

and do it like this:

 {% load render_table from django_tables2 %} {% render_table table %} <!-- Here I am passing queryset --> 
+5
source

There was the same problem. I forgot to add SingleTableMixin to view class options

+1
source

Similar to what Sharpless512 said, but in my case I forgot to update my view from ListView to SingleTableView

0
source

Source: https://habr.com/ru/post/985296/


All Articles