6

我是否正确理解“从 django.views.generic 导入 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 调用是否有快速的内联替换,还是需要更多的根除?

谢谢,

4

2 回答 2

9

django.views.generic.list_detail在 Django 1.3中已弃用:

从 Django 1.3 开始,基于函数的通用视图已被弃用,取而代之的是基于类的方法。

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

于 2013-03-25T21:04:18.467 回答
7

After importing django.views.generic.list.ListView

You just need to change list_detail.object_detail to ListView.as_view()

于 2013-03-27T20:16:48.903 回答