尝试使用django_tables2时出现以下错误
ValueError at /adm/appt/
Expected table or queryset, not str
我已经对包运行了所有更新和升级 错误
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
查看:我认为我正在正确初始化表以及发送查询集
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>
表
import django_tables2 as tables
from .models import Appointment
class AppointmentTable(tables.Table):
class Meta:
model = Appointment
template_name = 'django_tables2/bootstrap.html'
答案 0 :(得分:1)
调用模板标记的方式是错误的 - 视图上下文中没有AppointmentTable
,因此出错。改变如下:
{% render_table table %}
table
是您在视图中提供给render()
方法的上下文变量。