'ShortWriteForm'对象没有属性'request'

时间:2014-04-24 18:00:01

标签: python django django-forms django-views

我在django中有关于attributeError的问题:

from postman.forms import BaseWriteForm
from postman.fields import CommaSeparatedUserField
class ShortWriteForm(BaseWriteForm):
    recipients = CommaSeparatedUserField(
        label=(_("Recipients"), _("Recipient")),
        help_text='',
        widget=forms.HiddenInput()
    )
    subject = forms.CharField(
        initial="Kurze Nachricht",
        widget=forms.HiddenInput()
    )
    image = forms.ImageField(
        widget=forms.ClearableFileInput(attrs={'class': 'hidden'}),
        required=False
    )

    class Meta(BaseWriteForm.Meta):
        fields = ('recipients', 'subject', 'body', 'image')

    def save(self, *args, **kwargs):
        recipient = self.cleaned_data["recipients"][0]
        is_succesful = (
            super(ShortWriteForm,self).save(
                recipient=recipient,*args, **kwargs))
        if self.request and self.request.FILES:
            att_form = AttachmentImageForm(
                self.instance, self.request.POST, self.request.FILES)
            if att_form.is_valid():
                att_form.save()
        return is_succesful

类ShortWriteView(postman_views.riteView):

def get_initial(self):
    initial = super(ShortWriteView, self).get_initial()
    recipient = self.kwargs.get('recipients')
    self.recipient = get_object_or_404(User, username=recipient)
    return initial

def get_context_data(self, **kwargs):
    context = super(ShortWriteView, self).get_context_data(**kwargs)
    context['recipient'] = self.recipient
    return context

我收到了这个错误:

例外值:
'ShortWriteForm'对象没有属性'request'

0 个答案:

没有答案