django-tables2 linkColumn访问器 [英] django-tables2 linkColumn accessor
问题描述
我一直在使用我喜欢的 django-tables2 陷入一些问题
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')])
我一直试图用它来没有成功...此示例将使用哪些视图和模板?我认为url可能有问题,但是我不确定这是什么...谁能解释: 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')]
推荐答案
args = [A('pk')]
是从中显示表格的模型的主键.您的示例将创建一个名称"列,其中单元格内容< a href ="/people/pk"></a>
pk将作为主键(数字).该视图将为 views.people_detail
,模板将为您在此视图中定义的任何内容...
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...
以下是文档的链接: django-tables2 doc
希望这对您有帮助...
Hope this helps...
这篇关于django-tables2 linkColumn访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!