问题描述
我正在尝试使用 django-tables2 为我的应用程序创建一些表,但遇到了一些困难.我使用的是 Python 2.7 和 Django 1.7.我正在学习教程,但遇到了问题.
I am trying to create some tables for my application using django-tables2 and running into some difficulties. I am using Python 2.7, and Django 1.7. I am following the tutorial, and I ran into problems.
我到了需要创建用于自定义的 Table 类的地步.但是,每当我这样做时,都会出现以下错误:
I reach the point where I need to create a Table class for customization. However, whenever I do so, I get the following error:
预期的表或查询集,而不是str".
在做了一些之后研究 看起来我使用的是旧版本的 django-tables2.但是,我昨天刚刚使用 pip install django-tables2
安装了它,并在半小时前更新了它.知道如何让 django-tables2 正常工作吗?
After doing some research it looks like I am using an older version of django-tables2. However, I just installed it yesterday using pip install django-tables2
and updated it a half an hour ago. Any idea how I can get django-tables2 to work properly?
编辑 - 问题已解决.我使用的是 {% render_table people %}
而不是 {% render_table table %}
EDIT - Problem solved. I was using {% render_table people %}
instead of {% render_table table %}
推荐答案
我也遇到了这个问题.您应该做的第一件事是检查您的更新:
I encountered that problem, too. The first thing you should do is to check your updates:
sudo pip install django-tables2 --upgrade
sudo pip install django-tables2-reports --upgrade
升级也没有解决我的问题.
如果您已经升级了这些版本.你应该检查你的实现.如果您使用的是基于类的视图并且您可能实现了视图、模板、表.您可能忘记了网址:
Upgrades didn't fix my problem either.
If you have already upgraded version of these. You should check your implementation. If you are using Class Based View and you probably implemented the view,template,table. You probably forget the urls:
/* I give the example with respect to other post*/
urls.py /*Same dic with table.py,models..etc*/
from .views import SomeTableView
urlpatterns = patterns('',
url(r"^$", SomeTableView.as_view(), name="index"),
)
如果它不是您网站的索引,您可能必须更改 r"^$"
和 name="index"
If it is not index of your website you have to probably change the r"^$"
and name="index"
这篇关于使用 django-tables2 时出错 - 预期的表或查询集,而不是“str"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!