Search code examples
djangodjango-tables2

ValueError at /adm/appt/ Expected table or queryset, not str


Getting the following error when trying to use django_tables2

ValueError at /adm/appt/
Expected table or queryset, not str

I have run all the updates and upgrades on the packages Error

 Request Method:    GET
    Request URL:    http://127.0.0.1:8000/adm/appt/
    Django Version: 2.0.3
    Exception Type: ValueError
    Exception Value:    
    Expected table or queryset, not str
    Exception Location: C:\ProgramData\Anaconda3\lib\site-packages\django_tables2\templatetags\django_tables2.py in render, line 147
    Python Executable:  C:\ProgramData\Anaconda3\python.exe
    Python Version: 3.6.3

View: Think i'm initializing the table properly as well as sending the queryset

def ApptView(request):
    table = AppointmentTable(Appointment.objects.all())
    model = Appointment
    table_class = AppointmentTable
    filterset_class = AppointmentFilter
    RequestConfig(request).configure(table)
    return render(request,'adm/index2.html', {'table': table})

HTML

{% load render_table from django_tables2 %}


<body>


          {% render_table AppointmentTable %}


</div>


</body>

Tables

import django_tables2 as tables
from .models import Appointment

class AppointmentTable(tables.Table):
    class Meta:
        model = Appointment
        template_name = 'django_tables2/bootstrap.html'

Solution

  • The way you are calling the template tag is wrong - there is no AppointmentTable in your view context, hence the error. Change it as follows:

    {% render_table table %}
    

    Where table is the context variable that you've supplied to the render() method in your view.