gpt4 book ai didi

Django-tables2 不排序

转载 作者:行者123 更新时间:2023-12-04 00:46:36 24 4
gpt4 key购买 nike

我使用 django-tables2 显示数据库表。一切正常,但单击列标题不会按该列排序。标题是可点击的,但在它们的 html 中没有 url 文本,例如:

<div class="table-container">
<table class="paleblue"><thead><tr><th class="id orderable sortable"><a href="">ID</a>
</th><th class="orderable sortable system"><a href="">System</a></th> ...

我检查了 django-tables2 模板源,它是这样说的:

... <a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}"> ...

我不明白。

我只能通过在 view.py 中设置 order_by 来进行排序:

class ResultsTable(tables.Table):
class Meta:
model = Performance
attrs = {'class': 'paleblue'}
order_by_field = True

def result(request, system):
results = Performance.objects.filter(system__name=system)
table = ResultsTable(results, order_by=('<any column name from Performance>',))
RequestConfig(request).configure(table)
return render_to_response('result.html', {'table': table})

但这显然只适用于一列,我想单击列以选择要排序的列。

这是我对docs的理解按列排序应该“开箱即用”,这是正确的,还是我做错了什么?

最佳答案

遇到了同样的问题,只是我错过了

django.core.context_processors.request

来自 settings.py 中的 TEMPLATE_CONTEXT_PROCESSORS

关于Django-tables2 不排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10992090/

24 4 0