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

标签 python django

我是否正确理解“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/

相关文章:

python - iframe 不在 ipython-notebook 中呈现

python - 我如何检测 dynamodb2 中未写入的项目?

c++ - 如何将 Python 中的脚本转换为 C++?

django-allauth 在回调时给出 403 禁止

用日期范围填充行的 Pythonic 方法

python - 带有预告片值的嵌套 while 循环

ajax - 使用 Ajax 调用更新 Django View

mysql - 将 django 与 WSGI 一起使用时导入错误

django rest 框架 - 如何将查询参数传递给外键序列化程序?

python - AttributeError: 'Settings' 对象没有属性 'ROOT_URLCONF'