'How do I preserve search result in Django pagination

I am new to Django and I have develop form with Country and State field from the Profile Model. If I search for country and a particular state, I want a list of persons belonging to that country and state to display and paginated. And if the records are in multiple pages then I should be able to click on individual pages that follow to view the searched results on those pages without losing the search results.

Here is my views code with pagination.

def search_applicants(request):

form = ApplicantsSearchForm(request.GET or None)
if form.is_valid():
    list_submited = Profile.objects.filter(
        nation__icontains=form.cleaned_data['nation'],
        state__icontains=form.cleaned_data['state']
    )
else:
    list_submited = submited_apps.objects.all()

paginator = Paginator(list_submited, 5)
page = request.GET.get('page')
paged_listApps = paginator.get_page(page)

context = {
'list_applicants':paged_listApps,
'form':form,


}

return render(request, 'user/list_applicants.html',context)

I have got the pagination of all records from the Profile Model but any time I perform a search and try to click on the pagination tabs the search result is get scattered and returns to all the list items in the database.



Solution 1:[1]

On the front-end you need to submit your search data when clicking on your pagination tabs as well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fictionalPlant