1

我正在升级到 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",)

)
4

1 回答 1

0

视图.py

class BlogDetailView(DetailView):
    model = Blog
    template_name = 'idea/link_confirm_vote.html'

网址.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'
    ),
)
于 2013-02-28T05:51:03.613 回答