Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango pagination error
    text
    copied!<p>I have created a Django application. There is a filtering functionality in my application. The filtered data is shown in a separate page.</p> <p>Now I want to give Django Pagination to the filtered list page. While doing it, I came into this error. The pagination is shown at the bottom of the page with showing the correct number of pages NEXT.</p> <p>But while clicking on the 'Next Page' in paginator it redirects me to my home page (/employeeList).</p> <p>I suppose it is because of an <code>HttpResponseRedirect (return HttpResponseRedirect('/employeeList'))</code> I give inside the <code>filter()</code> which is used in some cases. I will paste my filter() and the HTML for pagination.</p> <pre><code>def filter(request): val2='' val3='' newData='' if request.GET.has_key('choices'): val2=request.GET.get('choices') if request.GET.has_key('textField'): val3=request.GET.get('textField') if request.POST: val2=request.POST.get('choices') val3=request.POST.get('textField') if val2=='Designation': newData = EmployeeDetails.objects.filter(designation=val3) flag=True elif val2=='Name': newData = EmployeeDetails.objects.filter(userName__icontains=val3) flag=True elif val2=='EmployeeID': newData = EmployeeDetails.objects.filter(employeeID=val3) flag=True elif val2=='Project': newData = EmployeeDetails.objects.filter(project=val3) flag=True elif val2=='DateOfJoin': newData = EmployeeDetails.objects.filter(dateOfJoin=val3) flag=True else: return HttpResponseRedirect('/employeeList') if request.POST.get('sortAscendValue'): newData = newData.order_by('userName') elif request.POST.get('sortDescendValue'): newData = newData.order_by('-userName') paginator = Paginator(newData, 10) try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: contacts = paginator.page(page) except (EmptyPage, InvalidPage): contacts = paginator.page(0) return render_to_response('filter.html',{'newData':newData,'emp_list': contacts,'val2':val2,'val3':val3,'flag':flag,'emp_list': contacts}) </code></pre> <p><strong>filter.html</strong></p> <pre><code>&lt;div class="pagination" &gt; &lt;span class="step-links"&gt; {% if emp_list.has_previous %} &lt;a href="?page={{ empl_list.previous_page_numbe }}"&gt;Previous&lt;/a&gt; {% endif %} &lt;span class="current"&gt; Page {{ emp_list.number }} of {{ emp_list.paginator.num_pages }}. &lt;/span&gt; {% if emp_list.has_next %} &lt;a href="?page={{ emp_list.next_page_number }}"&gt;Next&lt;/a&gt; {% endif %} &lt;/span&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload