【发布时间】:2016-09-08 16:38:43
【问题描述】:
我正在关注 Django-tables2 教程(可在此处找到:https://django-tables2.readthedocs.io/en/latest/pages/tutorial.html)。到目前为止,我已经修复了所有错误,但我遇到了一个我无法解决的错误。它说我的代码需要一个表或查询集,而不是字符串。
我环顾四周,这个问题的所有解决方案都归咎于版本过时,但我已经更新了它,我仍然得到这个错误。
有人知道我做错了什么吗?
这是我的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()})
这是我的models.py:
from django.db import models
class people(models.Model):
name = models.CharField(max_length = 40, verbose_name = 'Full Name')
这是我的模板.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>
【问题讨论】:
-
您将“obj”返回到模板,而不是“人”
标签: python django django-tables2