django-tables2 link列访问器

发布于 2024-11-10 11:01:55 字数 794 浏览 5 评论 0原文

我一直在使用我喜欢的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┾廆蒐ゝ 2024-11-17 11:01:55

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文