我正在升级到Django 1.5,后者已经弃用了通用视图。我正在使用django-voting,它使用了通用视图。我不知道如何将其转换为基于类的视图:
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 :(得分:0)
views.py
class BlogDetailView(DetailView):
model = Blog
template_name = 'idea/link_confirm_vote.html'
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'
),
)