首页 新闻 会员 周边 捐助

'PrivateletterForm' object has no attribute 'cleaned_data'

0
悬赏园豆:30 [已关闭问题] 关闭于 2012-06-10 17:24

我的model:

class Privateletter(models.Model):

  from_m = models.ForeignKey(User,related_name='send')
  to_m = models.ForeignKey(User,related_name='to')
  content = models.CharField(max_length=300)
  sendtime = models.DateTimeField(auto_now_add=True)
  #session = models.ForeignKey(Session,related_name='conversation')
  EXIST = 1
  NOEXIST = 0
  STATUS = (
      (EXIST,"exist"),
      (NOEXIST,"noexist"),
        )
  sends = models.IntegerField(choices=STATUS,default=EXIST)
  receives = models.IntegerField(choices=STATUS,default=EXIST)
  def __unicode__(self):
  return '%s发给%s的私信:%s'         (self.from_m.username,self.to_m.username,self.content)

 

我的form:

class PrivatelettersForm(forms.ModelForm):
 content = forms.CharField(max_length=150,widget = forms.Textarea({'size':6000}))
 class Meta:
  model = Privateletter
  exclude = ['sendtime','sends','from_m','receives','to_m'] 

 

我的view:

@csrf_exempt 
@login_required
def replyp(request,privateletter_id):
 user1 = request.user
 p = Privateletter.objects.get(id=privateletter_id)  
 if p.from_m == user1:
  user2 = p.to_m
 else:
  user2 = p.from_m
 if request.method == 'POST':
   form = PrivatelettersForm(request.POST)
   if form.is_valid:
    p = Privateletter.objects.create(request,
                    from_m = user1,
                    to_m = user2,
                    content = form.cleaned_data['content'],)
    p.save()
    return HttpResponseReirect('/accounts/privateletter/')  
   else:
    return HttpResponse('the data is invalid')                          
 else:
  form = PrivatelettersForm()
  return render_to_response('replyp.html',{'form':form})

 

这段程序是用私信的form做一个回复功能,但是总是出现报警:

'PrivateletterForm' object has no attribute 'cleaned_data'

我查了文档 ,这个报警是肯能数据无效但我的程序form.is_valid无效的话,会转入一个错误页面!红色的标志是报警的地方。各位能帮我看下问题出在什么地方?

pyther的主页 pyther | 初学一级 | 园豆:159
提问于:2012-06-09 15:25
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册