Django表2中的链接列

时间:2016-07-25 15:29:16

标签: django django-tables2

我目前正在尝试将Link column添加到我已经使用Django表2创建的表中。

我使用文档中的以下代码

class PeopleTable(tables.Table):
    name = tables.LinkColumn('people_detail', text='static text', args=[A('pk')])

view.py

urlpatterns = patterns('',
    url('people/(\d+)/', views.people_detail, name='people_detail')
)

问题是,当我尝试加载我的网页时,我收到以下错误: Reverse for 'people_detail' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

有人能在这看到问题吗?

编辑:我的url.py如下所示:

urlpatterns = [

url(r'^$', views.IndexView, name='index'),

url(r'^Search/$', views.SearchView, name='Search'),

url(r'^people/(\d+)/$', views.myview,{}, name='people_detail'),

url(r'^comment/$', views.LicenseComment, name='comment'),

url(r'^copyLicense/$', views.copyLicense, name='Copy'),

url(r'^download/$', views.download, name='Download'),

url(r'^AddMod/$', views.addModule, name='addMod'),

url(r'^removeMod/$', views.removeModule, name='removeMod'),

url(r'^login/$', views.Login.as_view(), name='login'),

url(r'^logout/$', views.LogOut, name='logout'),

url(r'^create/$', views.get_name, name='create'),

url(r'^NewLicense/$', views.NewLicense.as_view(), name='NewLicense'),

url(r'^LicenseCharts/$', views.Chart.as_view(), name='ViewChart'),

url(r'^Advancedsearch/$', views.Adsearch.as_view(), name='AdSearch'),

url(r'^AdvancedRequest/$', views.AdvancedRequest, name='AdvancedRequest'),

url(r'^EditLicense/$', views.EditLicense.as_view(), name='EditLic'),

url(r'^Profile/$', views.profileView.as_view(), name='profile'),

url(r'^GlobalLog/$', views.LogFile.as_view(), name='LogFile'),

]

此外,如果我从创建链接列的位置删除text='static files',则不再显示此错误,但该表只包含名为Name的列,该列仅包含短划线

2 个答案:

答案 0 :(得分:2)

如果您将urls.py包含在命名空间中,则必须在定义链接列时包含命名空间。例如:

class PeopleTable(tables.Table):
    name = tables.LinkColumn('myapp:people_detail', text='static text', args=[A('pk')])

答案 1 :(得分:1)

类似情况

我的应用名称-“ ecart”

url.py (在ecart应用程序中)
path(“ ecart / edit / ...”,edit_ecart,name =“ edit_ecart”)

tables.py (存在于相同的层次结构下,即ecart应用程序)

从django_tables2.utils

导入A
将django_tables2导入为表格

CartTable(tables.Table)类:
edit_col = table.LinkColumn('edit_ecart',text ='EDIT',args = [A('pk')])
----------
----------

这将把EDIT超链接列显示为表中的最后一列
注意:我不需要添加名称空间名称,即“ ecart:edit_ecart”,因为上述两个文件都位于同一层次结构中