Django - 从功能视图到泛型类视图

时间:2018-05-22 09:14:46

标签: django django-views

我有generic class view,我正试图在def view_events (request): template ='appform/view_events.html' items = Event.objects.filter(owner=request.user) pages = pagination(request,items, num = 10) print(pages) context = { 'items': pages[0], 'page_range': pages[1], } return render(request, template, context) 中对其进行转换:

  

原件:

class ViewEvents(generic.ListView):

    template_name = 'app/view_events.html'
    model = Event
    context_object_name = 'events'
    pagination = ???

    def get_queryset(self):

        return Event.objects.filter(owner = self.request.user)
  

通用类视图:

generic class view
编辑:我已经使用this作为分页,这是一个自定义分页符。我想问的问题是如何在class ViewEvents(generic.ListView): template_name = 'app/view_events.html' model = Event context_object_name = 'items' def get_queryset(self): return Event.objects.filter(owner = self.request.user) def get_context_data(self, **kwargs): context = super(ViewEvents, self).get_context_data(**kwargs) objects_all = Event.objects.filter(owner = self.request.user) pages = pagination(self.request, objects_all, num = 10) context['items'] = pages[0] context['page_range'] = pages[1] return context 中实现它?

后来编辑:这使它运作起来,以防它可能对某人有用:)

ValueError: Shape of passed values is (20, 32), indices imply (20, 38)

0 个答案:

没有答案