关于django-tables2的链接列 [英] The linkcolumn about django-tables2
问题描述
我使用django-tables2在页面中显示一些数据,现在我想使单元格链接到某个URL,但是链接URL如:
I use django-tables2 to show some data in page,and now I want to make the cell link to some url,but the link url such as :
url(r'^(?P\w +)/(?P\d +)/ $','pool.views.pooldatestock',
name = pool_date_stock),
url(r'^(?P\w+)/(?P\d+)/$', 'pool.views.pooldatestock', name="pool_date_stock"),
,我阅读了django-tables2的文档,但找不到有关此问题的示例。
and I read the documents of django-tables2,but I can't find some excample about this problem.
表格显示在页面的网址中,就像:http://127.0.0.1:8000 / pool / 20111222 /
the tables show in the page's url just like:http://127.0.0.1:8000/pool/20111222/
I尝试在我的tables.py中写这个:
I try to write this in my tables.py :
class PoolTable(tables.Table):
number = tables.LinkColumn('pool.views.pooldatestock', args=[A('number')])
date = tables.Column()
然后我尝试写:
class PoolTable(tables.Table):
number=tables.LinkColumn('pool.views.pooldatestock',
args=[A('date')],
kwargs=A('number')])
date = tables.Column()
但这也是错误的...
but it's error too...
有人可以告诉我如何解决这个问题?还是应该创建自己的没有jango-tables的表视图。
somebody can tell me how to solve this problem?or should I create my own table view, without django-tables.
感谢和圣诞快乐:)
推荐答案
对于<要为code> kwargs 参数提供一个列表,则应为它添加一个 dict
。但是,由于您的网址未使用命名组,因此仍然不需要关键字参数。只需将两个URL参数放在 args
参数中:
It makes no sense for the kwargs
parameter to be given a list, it should be given a dict
. However as your URL doesn't used named groups, it doesn't need keyword arguments anyway. Just put both URL parameters in the args
parameter:
class PoolTable(tables.Table):
number = tables.LinkColumn('pool.views.pooldatestock',
args=[A('date'), A('number')])
date = tables.Column()
这篇关于关于django-tables2的链接列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!