2013-02-28 120 views
1

我正在升級到Django 1.5,此後不推薦使用通用視圖。我使用的是使用通用視圖的django-voting。我不知道如何翻譯成基於類此觀點:翻譯Django通用視圖的最佳方法

from django.conf.urls.defaults import * 
from django.views.generic.list_detail import object_list 
from django.core.context_processors import request 
from django.shortcuts import get_object_or_404, render_to_response 
from blog.models import Blog 
from voting.views import vote_on_object 
from voting.models import Vote 
import operator 

urlpatterns = patterns('', 

    url(r'^links/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$', 
     vote_on_object, 
     dict(
      model=Blog, 
      template_object_name='link', 
      template_name='blog/link_confirm_vote.html', 
      allow_xmlhttprequest=True, 
      ), 
     name="link_vote",) 

) 
+0

object_list中在Django被刪除1.5 – 2013-04-18 02:57:23

回答

0

views.py

​​

urls.py

from .views import BlogDetailView 

urlpatterns = patterns('', 
    url(
     regex=r'^links/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$', 
     view=BlogDetailView.as_view(), 
     name='link_vote' 
    ), 
) 
+0

感謝快速反應!我認爲這是正確的軌道,但vote_on_object模塊不被識別。 :( – user1462141 2013-02-28 06:42:58

+0

我在看過這個文檔之前問:[文檔鏈接](https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#django.views.generic。 list.ListView),我使用的是listview,但沒有骰子。 – user1462141 2013-02-28 06:44:44

+0

爲什麼不改變link_vote到vote_on_object? – princess 2013-02-28 06:48:02