python - Django filters with pagination not keeping state -
this question exact duplicate of:
in django project using django filters , pagination. when click next link go next page, lose state. have tried ideas here nothing has done trick yet. ideas on why happens?
html
<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>
view
def relations(request): annotations.filters import relationsetfilter qs = relationset.objects.all() filtered = relationsetfilter(request.get, queryset=qs) qs = filtered.qs r in qs: print r.__dict__ paginator = paginator(qs, 20) page = request.get.get('page') try: relations = paginator.page(page) except pagenotaninteger: # if page not integer, deliver first page. relations = paginator.page(1) except emptypage: # if page 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)
urls
url when filters applied:
/relations/?createdby=&occursin=&createdafter=&createdbefore=&terminal_nodes=&project=1
url when switch page:
/relations/?page=2
you not passing parameters (ex. createdby ) in context null in html
Comments
Post a Comment