[Answer]-Django Paginator Error

1👍

def Boat(request ,animal_id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('world:LoginRequest'))

    picture = Picture.objects.filter(board=animal_id)

    paginator = Paginator(picture,1)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        picture = paginator.page(page)
    except (EmptyPage, InvalidPage):
        picture = paginator.page(paginator.num_pages)

    picture = paginator.page(paginator.num_pages)

    return render(request,'boat.html',{'picture':picture })

0👍

#this is view 
#this is views files
@login_required(login_url='/login')

# class Base_page_list2(ListView):
def Base_page_list(request,*args, **kwargs):

    # tiket      = Tiket.objects.all()
    
    # lastest_tiket =Tiket.objects.order_by('-id').all()[:8]
    tiket_list = Tiket.objects.all()
    paginator  = Paginator(tiket_list,2)

    page = request.GET.get('page')
    page_obj = paginator.get_page(page)

    context ={
        'tiket':None,
        'page_obj':page_obj,
        

        
    }
    context['tiket']=['page_obj']
    
    
    if request.user.is_superuser:
        context['tiket']= Tiket.objects.all()
             
    elif not request.user.is_hrm:
        raise Http404('شما نمی توانید به این صحفه دسترسی داشته باشید')
    
    elif request.user.is_mis :
        context['tiket']= Tiket.objects.filter(status_tag='s')
    
    elif request.user.is_mali:
        context['tiket']=Tiket.objects.filter(status_tag='m')
    
    elif request.user.is_mosh:
        context['tiket']=Tiket.objects.filter(status_tag='c')

    elif request.user.is_modir:
        context['tiket']=Tiket.objects.filter(status_tag='b')
    
    elif request.user.is_kz:
        context['tiket']=Tiket.objects.filter(status_tag='k')    
    
    elif request.user.is_pa:
        context['tiket']=Tiket.objects.filter(status_tag='p')  
    
    else:
       context['page_obj']['tiket']=Tiket.objects.filter(author=request.user) 
return render(request,'hrm_account/base.html',context)
`enter code here`error

  File "/home/ali/Desktop/testsharen2/sharen/sharen_hrm/views.py", line 128, in Base_page_list
    context['page_obj']['tiket']=Tiket.objects.filter(author=request.user)
TypeError: 'Page' object does not support item assignment
👤ali.py

Leave a comment