Search code examples
pythondjangodjango-tables2

Django-tables2: ValueError at /interactive_table/ Expected table or queryset, not str


I was following along with the tutorial for Django-tables2 tutorial (which can be found here: https://django-tables2.readthedocs.io/en/latest/pages/tutorial.html). I've fixed all the errors up until now, but I've hit one that I cannot solve. It says that my code expected a table or queryset, not a string.

I've looked around, and all the solutions to this problem all blame the version being out of date, but I have updated it and I still get this error.

Does anybody know what I'm doing wrong?

Here is my views.py:

from django.shortcuts import render
from interactive_table import models

def people(request):
    return render(request, 'template.html', {'obj': models.people.objects.all()})

Here is my models.py:

    from django.db import models

class people(models.Model):
    name = models.CharField(max_length = 40, verbose_name = 'Full Name')

Here is my template.html:

{# tutorial/templates/people.html #}
{% load render_table from django_tables2 %}
<!doctype html>
<html>
    <head>
        <link rel="stylesheet" href="{{ STATIC_URL }}django_tables2/themes/paleblue/css/screen.css" />
    </head>
    <body>
        {% render_table people %}
    </body>
</html>

Solution

  • change obj to people in render function.

    Try to understand how templates and template variables work with django.

    Documentations might be a good place to look