0

I want to do pagination. And when I press to button 'Next' on my page, my website breaks down.

It happens because for the next page variable 'searched' is empty. 'Searched' is name of tag input in my form

I don't know how to save variable 'searched' for the next page.

def search(request):

    if request.method == 'GET':
    
        # API-call 
        searched = request.GET.get('searched')
        headers = { 'Authorization' : basic_auth(login, password)}
        params = {'PIN':searched,'VKORG':'4000','KUNNR_RG':'43282126'}
        res = requests.post(url_for_search,headers=headers,data=params)

        if 200 <= res.status_code < 300 :
            
            names = get_unique_names(res.json())

            if not Profile.objects.filter(NAME__in = names).exists():
            
                # Deserialization
                serializer = ProfileSerializer(data=res.json()['RESP'],many = True)
                serializer.is_valid()
                serializer.save()

        # Getting data from ORM
        products = Profile.objects.filter(NAME__in = names).distinct()
            
        # Pagintation
        p = Paginator(products,10)
        page = request.GET.get('page')
        page_obj = p.get_page(page)

        return render(request,template,{"page_obj":page_obj,'searched':searched})                               

    else:
        return HttpResponse('Error')

Maybe you can help me? :)

0 Answers0