django-tables2 link列访问器
我一直在使用我喜欢的 django-tables2 ,但遇到了一些问题
我正在尝试制作一个表格,其中单元格链接到另一个表格或外部链接 文档中的示例是:
models.py
class Person(models.Model):
name = models.CharField(max_length=200)
urls.py
urlpatterns = patterns('',
url('people/(\d+)/', views.people_detail, name='people_detail')
)
tables.py
from django_tables.utils import A # alias for Accessor
class PeopleTable(tables.Table):
name = tables.LinkColumn('people_detail', args=[A('pk')])
我一直在尝试使用它但没有成功...... 此示例适用的视图和模板是什么? 我认为网址可能有问题,但我不确定它是什么...... 谁能解释一下:args=[A('pk')]
I have been using django-tables2 which I like, but i run into some problems
I am trying to make a table in which cells link out to a different table, or an outside link
the example in the documentation is :
models.py
class Person(models.Model):
name = models.CharField(max_length=200)
urls.py
urlpatterns = patterns('',
url('people/(\d+)/', views.people_detail, name='people_detail')
)
tables.py
from django_tables.utils import A # alias for Accessor
class PeopleTable(tables.Table):
name = tables.LinkColumn('people_detail', args=[A('pk')])
I have been trying to use this to no success...
What would be the view and template that would go with this example?
I think there might be a problem with the url but I am not sure what it is...
Can anyone explain: args=[A('pk')]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
args=[A('pk')]
是您要显示表格的模型的主键。您的示例将创建一个列“名称”,其中单元格内容pk 将是主键(数字)。
视图将是views.people_detail,模板将是您在此视图中定义的任何内容...
这是文档的链接:django-tables2 doc
希望这有帮助...
args=[A('pk')]
is the primary key of the model from which you're displaying the table. Your example would create a column 'Name' with the cell content<a href="/people/pk"></a>
pk would be the primary key (number).The view would be
views.people_detail
and the template would be whatever you've defined in this view...Here's the link to the doc: django-tables2 doc
Hope this helps...