从django通用视图更改为基于类的视图

时间:2013-12-02 02:35:05

标签: python django

这是我的blog / urls.py文件,我在Django 1.6中,当我运行我的服务器它抱怨:无法导入django.views.generic.date_based.archive_index。父模块django.views.generic.date_based不存在。请帮我解决这个问题。这是我正在使用http://www.webmonkey.com/2010/02/Use_URL_Patterns_and_Views_in_Django

的教程
 from django.conf.urls.defaults import *

 from djangoblog.blog.models import Entry

 from tagging.views import tagged_object_list



  info_dict = {

'queryset': Entry.objects.filter(status=1),

'date_field': 'pub_date',

   }



   urlpatterns = patterns('django.views.generic.date_based',

(r'(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$', 'object_detail', dict(info_dict, slug_field='slug',template_name='blog/detail.html')),

(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$', 'object_detail', dict(info_dict, template_name='blog/list.html')),

(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/$','archive_day',dict(info_dict,template_name='blog/list.html')),

(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/$','archive_month', dict(info_dict, template_name='blog/list.html')),

(r'^(?P<year>d{4})/$','archive_year', dict(info_dict, template_name='blog/list.html')),

(r'^$','archive_index', dict(info_dict, template_name='blog/list.html')),

1 个答案:

答案 0 :(得分:1)

django.views.generic.date_based.archive_index的新视图是django.views.generic.dates.ArchiveIndexView。有关与基于类的视图相关的其他迁移,请参阅https://docs.djangoproject.com/en/1.4/topics/generic-views-migration/