我使用的是较旧的教科书,并且指南告诉我在urls.py
from django.views.generic.list_detail import object_list, object_detail
from django.views.generic.create_update import create_update
据我了解,这些功能已在Django的早期版本中弃用-但我不知道现代的实现是什么。
是否还会影响我的网址格式?
url(r'^$', object_list, dict(display_info, allow_empty=True)),
url(r'^(?P<object_id>\d+)/$', object_detail, display_info),
url(r'^add/$', create_object, create_info),
感谢您的帮助。
答案 0 :(得分:1)
请使用
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView
from django.views.generic.edit import CreateView
代替
from django.views.generic.list_detail import object_list, object_detail
from django.views.generic.create_update import create_update
from django.contrib import admin
from django.urls import include
from django.conf.urls import url
from .views import SampleView
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^polls/', include('polls.urls')),
path('sample-app/', include('sample_app.urls')),
path('sample-view/', SampleView.as_view(), name="sample_view"),
]