问题
I think I'm missing something obvious here, but I've been stuck at this for so long, I had to post the question.
Link to screenshot
- When I click on the link generated in LinkColumn of django-tables2, it redirects back to the same page. Here's my code:
urls.py:
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'admin', views.admin, name='admin'),
url(r'admin/edit/(?P<pk>\d+)/', views.bug_edit, name='bug_edit'),
url(r'admin/delete/(?P<pk>\d+)/', views.bug_delete, name='bug_delete'),
)
views.py:
def bug_edit(request):
return HttpResponse('This is an edit page!')
def bug_delete(request):
return HttpResponse('This is a delete page!')
forms.py:
class SimpleTable(tables.Table):
edit_link = tables.LinkColumn('bug_edit', args=[A('pk')],
verbose_name='Edit', accessor='pk', attrs={'class':'edit_link'})
delete_link = tables.LinkColumn('bug_delete', args=[A('pk')],
verbose_name='Delete Bug', accessor='pk', attrs={'class':'delete_link'})
class Meta:
attrs = {'class' : 'paleblue'}
model = BugModel
I don't see the HttpResponse on clicking the links, as I should.
Thank you.
回答1:
The problem is your url patterns are missing ^ and $.
Without them, the 'admin' pattern is matching any url with 'admin' in it -- effectively masking the following patterns.
Try using this instead:
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^admin/$', views.admin, name='admin'),
url(r'^admin/edit/(?P<pk>\d+)/$', views.bug_edit, name='bug_edit'),
url(r'^admin/delete/(?P<pk>\d+)/$', views.bug_delete, name='bug_delete'),
)
来源:https://stackoverflow.com/questions/24868947/django-tables2-linkcolumn-link-doesnt-work