django-tables2 header 行 url 错误....无法排序

django-tables2 header row urls wrong....can't sort

我不知道如何解决这个关于 table 排序的问题: table 在此 url 处呈现: 127.0.0.1:8000/ip_teams/

但是当我点击列名对 table 进行排序时,url 变成了: 127.0.0.1:8000/?排序=名称 它排除了 "ip_teams/" 路径。

这是我的观点:

class FoundationIPTypeList(SingleTableView):

    model = tracker_models.FoundationIPType
    table_class = tables.FoundationIPTypeTable

这是我的 table:

class FoundationIPTypeTable(django_tables.Table):
    class Meta:
        model = FoundationIPType
        attrs = {'class': "table table-striped table-condensed table-hover"}
        fields = ["name", "help_contact_email"]

这是我的 urls:

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 %}

有什么想法有什么问题吗?似乎无法在任何地方找到答案。我认为这个功能开箱即用。

table header 行:

    <thead>
    <tr>


        <th class="name orderable"><a href="?sort=name&amp;name=unknown">Name</a></th>



        <th class="help_contact_email orderable"><a href="?sort=help_contact_email&amp;name=unknown">Help Contact Email</a></th>


    </tr>
</thead>

Django-tables2 使用添加排序参数的相对 url。只要文档不包含 base 标签,它就可以工作,该标签会更改页面中任何相关 URL 的基础。

删除 <base> 标签将解决您的问题。