gpt4 book ai didi

python - "from django.views.generic import list_detail"的当前 Django 是什么?

转载 作者:太空狗 更新时间:2023-10-30 00:28:21 24 4
gpt4 key购买 nike

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

谢谢,

最佳答案

django.views.generic.list_detaildeprecated in Django 1.3 :

From Django 1.3, function-based generic views have been deprecated in favor of a class-based approach.

使用django.views.generic.list.ListView相反。

关于python - "from django.views.generic import list_detail"的当前 Django 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15624509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com