如何在Django 1.7中对搜索结果进行分页?

时间:2017-02-24 03:25:18

标签: html django django-templates django-views

我的代码是一个非常适合我的寻呼机,但现在我想添加搜索选项,但我不知道如何将它与我的代码集成,我感谢所提供的所有帮助。

这是我的网址:

url(r'negocios/(?P<pagina>\d+)/$', NegociosView.as_view(),name='vista_negocios'),

这是我的观点:

class NegociosView(ListView):

def get(self, request, *args, **kwargs):


    pagina = kwargs['pagina']
    lista_negocios = Perfil.objects.all()
    paginator = Paginator(lista_negocios,2)
    try:
        page = int(pagina)
    except:
        page = 1
    try:
        nego = paginator.page(page)
    except(EmptyPage,InvalidPage):
        nego = paginator.page(paginator.num_pages)
    ctx = {'negocios':nego}
    return render_to_response('home/negocios.html',ctx,context_instance=RequestContext(request))

这是我的模板代码:

enter image description here

这是浏览器的视图: enter image description here

0 个答案:

没有答案
相关问题