' AddView'对象没有属性' render_to_response'

时间:2015-06-30 04:59:01

标签: django

我的view.py 是:

class AddView(BaseCreateView):
    template_name = 'add.html'
    model = Classname
    fields = '__all__'
    def get_success_url(self):
        return self.reverse('sitepro:list', kwargs=[])

    def get_context_data(self, *args, **kwargs):
        context = super(AddView, self).get_context_data(*args, **kwargs)
        context['form'] = ClassnameForm
        return context

    def form_valid(self, form):
        form.save()
        return super(AddView, self).form_valid(form)

    def form_invalid(self, form):
        return render_to_response(self.get_context_data(form=form))

我没有得到它想说的话,因为我included render_to_response。请有人帮我解决。

1 个答案:

答案 0 :(得分:2)

您不需要导入render_to_response,而是使用self.render_to_response,因为它来自BaseCreateView

This是基于类的视图的绝佳资源。