2013-03-25 21 views
1

近日筆者從Django的1.4遷移到Django的1.5,我得到這個錯誤Django的功能通用視圖遷移到基於類的觀點

ViewDoesNotExist: Could not import django.views.generic.date_based.archive_index. Parent module django.views.generic.date_based does not exist. 

谷歌搜索給我的是基於函數的觀點已經deprecieted。我正在嘗試遷移到基於類的視圖,但發現它很困難。這裏是我的views.py

from app.models import Season 
from django.conf.urls import * 
from cms.models import News, File 


def get_extra_context(): 
    past_seasons = Season.objects.filter(in_progress = False) 
    try: 
     current_season = Season.objects.get(in_progress = True) 
    except Season.DoesNotExist: 
     current_season = None 
    files = File.objects.all().order_by('-id')[:5] 
    output = { 
     'current_season': current_season, 
     'past_seasons': past_seasons, 
     'files': files, 
     } 
    return output 

dictionary = { 
    'queryset': News.objects.all(), 
    'date_field': 'date', 
    'extra_context': get_extra_context(), 
} 


urlpatterns= patterns(
    'django.views.generic.date_based', 
    url(
     r'(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 
     'object_detail', 
     dict(dictionary, slug_field = 'slug', template_name = 'cms/news/object.html'), 
     name='object' 
    ), 
    url(
     r'^$', 
     'archive_index', 
     dict(dictionary, template_name = 'cms/news/list.html'), 
     name='list' 
    ) 
) 

我無法將其轉換爲基於類的視圖。可以任何身體幫助。詞典是我想要放入上下文的對象。

在此先感謝。

//鼠標

回答

0

這裏是我是如何做到的。

urlpatterns = patterns(
    '', 
    url(
     r'(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 
     DateDetailView.as_view(
      model = News, 
      date_field = 'date', 
      slug_field = 'slug', 
      template_name = 'cms/news/object.html', 
      #dict = dictionary, 
     ), 
     name='object' 
    ), 
) 
相關問題