django迁移到旧应用程序的1.6版本:ListView
我正在将我们的旧应用程序迁移到django 1.6 现在,一些视图已通过这种方式编程:django迁移到旧应用程序的1.6版本:ListView,django,listview,migration,Django,Listview,Migration,我正在将我们的旧应用程序迁移到django 1.6 现在,一些视图已通过这种方式编程: from django.views.generic.list_detail import object_list @render_to("items/index.html") def index(request): profile = request.user.get_profile() args = clean_url_encode(request.GET.copy().urlen
from django.views.generic.list_detail import object_list
@render_to("items/index.html")
def index(request):
profile = request.user.get_profile()
args = clean_url_encode(request.GET.copy().urlencode())
context = {
'is_dashboard': True,
'body_id': 'dashboard',
'object_list': None,
'args':args,
'show_in_process':False
}
return context
我知道我现在需要使用新的ListView,但是示例和文档似乎没有告诉我我的这个特殊情况:在上下文中传递的对象列表
如何调整此代码以使用新的基于类的泛型视图?我是否可以只使用
ListView.asView()
而不是'object\u list':无?
如果没有对象列表,为什么要使用ListView
?我认为TemplateView
应该做这项工作。您只需要覆盖获取上下文数据
并提供自定义上下文
class IndexView(TemplateView):
template_name = 'items/index.html'
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
profile = self.request.user.get_profile()
args = clean_url_encode(self.request.GET.copy().urlencode())
context.update({
'is_dashboard': True,
'body_id': 'dashboard',
'object_list': None,
'args':args,
'show_in_process':False
})
return context
谢谢@tuxcanfly,如果我理解的很好,每个这样的函数都会成为它自己的视图类?这对我们来说是相当大的迁移量…我明白了。不是所有函数,只是通用视图。