什么是当前的Django“来自django.views.generic import list_detail”?

时间:2013-03-25 20:50:16

标签: python django

我是否理解“来自django.views.generic import list_detail”已被弃用和/或从Django中移除?

如果是的话,适当的继任者是什么?

谢谢,

-

@Gareth,谢谢。

我有一个后续问题要问:如何使用ListView替换list_detail.object_detail?

仅在导入中更改的当前代码为:

from django.conf.urls.defaults import *
#from django.views.generic import list_detail
from django.views.generic.list import ListView

from announcements.models import Announcement
from announcements.views import *


announcement_detail_info = {
    "queryset": Announcement.objects.all(),
}

urlpatterns = patterns("",
    url(r"^(?P<object_id>\d+)/$", list_detail.object_detail,
        announcement_detail_info, name="announcement_detail"),
    url(r"^(?P<object_id>\d+)/hide/$", announcement_hide,
        name="announcement_hide"),
    url(r"^$", announcement_list, name="announcement_home"),
)

https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#listview似乎没有建议单个内联替换:

    url(r"^(?P<object_id>\d+)/$", list_detail.object_detail,
        announcement_detail_info, name="announcement_detail"),

如果有的话,它建议添加一个额外的模型,并建立该模型。

是否有快速的内联替换list_detail.object_detail调用,还是需要更多的连根拔除?

谢谢,

2 个答案:

答案 0 :(得分:7)

django.views.generic.list_detaildeprecated in Django 1.3

  

从Django 1.3开始,基于函数的通用视图已被弃用,转而采用基于类的方法。

改为使用django.views.generic.list.ListView

答案 1 :(得分:5)

导入django.views.generic.list.ListView

您只需将list_detail.object_detail更改为ListView.as_view()

即可