ValueError at /adm/appt/ Expected table or queryset, not str
ValueError at /adm/appt/ Expected table or queryset, not str
尝试使用 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
视图:认为我正在正确初始化 table 以及发送查询集
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'
您调用模板标记的方式是错误的 - 在您的视图上下文中没有 AppointmentTable
,因此出现错误。更改如下:
{% render_table table %}
其中 table
是您在视图中提供给 render()
方法的上下文变量。
尝试使用 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
视图:认为我正在正确初始化 table 以及发送查询集
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'
您调用模板标记的方式是错误的 - 在您的视图上下文中没有 AppointmentTable
,因此出现错误。更改如下:
{% render_table table %}
其中 table
是您在视图中提供给 render()
方法的上下文变量。