On Sun, May 6, 2012 at 10:56 PM, coded kid <duffleboi...@gmail.com> wrote: > I'm trying to paginate a page in order to display five statuses per > page. After inputting these codes, it fails to paginate. Below are the > codes for pagination and updating of status in my django app. > > > Views: > > def qask(request): > extra_data_context={} > #if there's nothing in the field do nothing. > if request. method=="POST": > form =AskForm(request.POST) > if form.is_valid(): > data=form.cleaned_data > newask=Ask( > user= request.user, > status=data['status'], > pub_date=datetime.datetime.now()) > newask.save() > extra_data_context.update({'AskForm':form}) > else: > form = AskForm() > extra_data_context.update({'AskForm':form}) > > extra_data_context.update({'Asks':Ask.objects.filter(user=request.user)})
So here you specify 'Asks' as all Ask objects associated with the current user. > > plan=Ask.objects.all() > paginator=Paginator(plan, 5) > > try: > page=int(request.GET.get('page','1')) > except ValueError: > page=1 > > try: > fp=paginator.page(page) > except (EmptyPage, InvalidPage): > fp=paginator.page(paginator.num_pages) Here you paginate all Ask objects, and don't do anything with pagination object. > return render_to_response > ('quik_ask.html',extra_data_context,context_instance=RequestContext(request)) > > Template: > {% block content %} > > > > {% for Ask in Asks %} > <tr> > <p> {{Ask.user}} </p> </strong> > <p>{{Ask.status}}</p> > <p>{{Ask.state}} | {{Ask.pub_date|timesince }} ago </p> > > </tr> > {% endfor %} > > <div class="pagination"> > <span class="step-links"> > {% if Asks.has_previous %} And here you start using 'Asks' in the template as though it had been paginated and was not a raw queryset. This is unlikely to work. When you paginate a queryset, you need to create a paginator object with that queryset, page the paginator to select an appropriate page, and then pass the page to the template. This is covered in mind numbing detail in the Django docs: https://docs.djangoproject.com/en/1.4/topics/pagination/#using-paginator-in-a-view Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.