在我的django项目中,我正在使用django过滤器和分页。当我点击下一个链接转到下一页时,我失去了我的状态。我已经尝试了here的一些想法,但还没有完成任何工作。关于为什么会发生这种情况的任何想法?
<div class="col-xs-4 clearfix text-center">
{% if relations.has_next %}
<div class="pull-right">
<a href="?page={{ relations.next_page_number }}{% if createdBy %}&createdBy={{ createdBy }}{% endif %}{% if project %}&project={{ project }}{% endif %}{% if createdBefore %}&createdBefore={{ createdBefore }}{% endif %}}">Next »</a>
</div>
{% endif %}
</div>
def relations(request):
from annotations.filters import RelationSetFilter
qs = RelationSet.objects.all()
filtered = RelationSetFilter(request.GET, queryset=qs)
qs = filtered.qs
for r in qs:
print r.__dict__
paginator = Paginator(qs, 20)
page = request.GET.get('page')
try:
relations = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
relations = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
relations = paginator.page(paginator.num_pages)
context = {
'paginator': paginator,
'relations': relations,
'params': request.GET.urlencode(),
'filter': filtered,
return render(request, 'annotations/relations.html', context)
应用过滤器时的网址:
/relations/?createdBy=&occursIn=&createdAfter=&createdBefore=&terminal_nodes=&project=1
我切换页面时的网址:
/relations/?page=2
答案 0 :(得分:0)
您没有在上下文中传递参数(例如created.yy),因此它们在HTML中始终为空