django-tables2标头行网址错误....无法排序 [英] django-tables2 header row urls wrong....can't sort
问题描述
我不知道如何解决有关对表格进行排序的问题:表在此URL呈现:127.0.0.1:8000/ip_teams/
I can't figure out how to solve this issue about sorting my table: table is rendered at this url: 127.0.0.1:8000/ip_teams/
但是当我单击列名对表进行排序时,URL变为:127.0.0.1:8000/?sort=名称它不包括"ip_teams/"路径.
but when I click on the name of the column to sort the table, url became: 127.0.0.1:8000/?sort=name it excludes the "ip_teams/" path.
这是我的观点:
class FoundationIPTypeList(SingleTableView):
model = tracker_models.FoundationIPType
table_class = tables.FoundationIPTypeTable
这是我的桌子
class FoundationIPTypeTable(django_tables.Table):
class Meta:
model = FoundationIPType
attrs = {'class': "table table-striped table-condensed table-hover"}
fields = ["name", "help_contact_email"]
这是我的网址:
urlpatterns = [
# url(r'^$', views.HomePageView.as_view(), name='home'), # Notice the URL has been named
url(r'^about/$', views.AboutPageView.as_view(), name='about'),
url(r'^ip_teams/$', views.FoundationIPTypeList.as_view(), name="ip_team_list"),
这是我的模板
{% extends "base.html" %}
{% load render_table from django_tables2 %}
{% block pagecontent %}
<h1><center>Foundation IP Teams</center></h1>
<div class="container">
<div class="panel panel-primary">
{% render_table table %}
</div>
</div>
{% endblock %}
任何想法有什么问题吗?似乎无法在任何地方找到答案.我认为该功能可以立即使用.
any ideas what is wrong? can't seem to find the answer anywhere. i thought this feature would work right out of the box.
表标题行:
<thead>
<tr>
<th class="name orderable"><a href="?sort=name&name=unknown">Name</a></th>
<th class="help_contact_email orderable"><a href="?sort=help_contact_email&name=unknown">Help Contact Email</a></th>
</tr>
</thead>
推荐答案
Django-tables2使用相对URL来添加排序参数.只要文档不包含 base
标记,它们会更改页面中任何相对URL的基数.
Django-tables2 uses relative urls which add the sorting parameter. This works as long as the document does not contain a base
tags, which change the base of any relative urls in the page.
删除< base>
标记将解决您的问题.
Removing the <base>
tag will fix your issue.
这篇关于django-tables2标头行网址错误....无法排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!