The linkcolumn about django-tables2

 ̄綄美尐妖づ 提交于 2019-12-05 23:12:16

问题


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"),

and I read the documents of django-tables2,but I can't find some excample about this problem.

the tables show in the page's url just like:http://127.0.0.1:8000/pool/20111222/

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()

and then I try to write:

class PoolTable(tables.Table):
    number=tables.LinkColumn('pool.views.pooldatestock',
                             args=[A('date')],
                             kwargs=A('number')])
    date = tables.Column()

but it's error too...

somebody can tell me how to solve this problem?or should I create my own table view, without django-tables.

Thanks.and Merry Christmas:)


回答1:


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()


来源:https://stackoverflow.com/questions/8613542/the-linkcolumn-about-django-tables2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!