Django:对象没有属性“对象”

时间:2018-12-20 12:48:36

标签: python django

我必须实现几种形式,因此我需要组合SingleObjectMixinTemplateView。我总是收到'AssignAttendee' object has no attribute 'object'。您知道我为什么收到该错误吗?

class AssignAttendee(SuccessMessageMixin, SingleObjectMixin, TemplateView):
    template_name = 'attendees/front/assign_attendee.html'
    success_message = _("Attendee has been successfully updated.")

    def get_object(self):
        return get_object_or_404(
            Attendee,
            ticket_reference=self.kwargs['ticket_reference'],
            ticket_code=self.kwargs['ticket_code'],
        )

    @cached_property
    def attendee_form(self):
        return AssignAttendeeForm(
            prefix='attendee',
            data=self.request.POST or None,
            # instance=self.attendee_contact,
        )

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context = {
            'attendee_form': self.attendee_form,
        }

1 个答案:

答案 0 :(得分:0)

问题是它丢失了:

def get(self, request, *args, **kwargs):
    self.object = self.get_object()
    return super().get(request, *args, **kwargs)