我正在尝试将我的项目从Django 1.4.5迁移到1.6.5
Django 1.4.5代码:
from django.views.generic.list_detail import object_list, object_detail
..
return object_list(request, groups, paginate_by = 20, template_object_name = 'group', extra_context = args)
return object_detail(request, queryset, id, template_object_name = 'group')问题:,上面的代码在1.6.5中看起来如何?
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
..
return ????发布于 2014-07-16 19:23:27
对于那些感兴趣的人,ListView的正确答案是:
class TestsListView(ListView):
extra_context = {}
def get_context_data(self, **kwargs):
context = super(TestsListView, self).get_context_data(**kwargs)
context.update(self.extra_context)
return context
...
callable = TestsListView.as_view(queryset = groups, template_name = None, paginate_by = 20, context_object_name = 'group_list', extra_context = args)
return callable(request)https://stackoverflow.com/questions/24760050
复制相似问题