我具有以下模型:如何在一個模板來顯示從數據庫中的數據
class comment(models.Model):
userid=models.CharField(max_length=140)
apparelid=models.IntegerField(blank=True)
desc=models.TextField(blank=True)
def __unicode__(self):
return self.userid
形式:
class commentForm(ModelForm):
class Meta:
model=comment
exclude=('userid','apparelid',)
和視圖如下:
def comment(request,title_id):
if request.method=='POST':
form=commentForm(request.POST)
if form.is_valid():
new=form.save(commit=False)
new.userid=request.user.username
new.apparelid=title_id
new.save()
return HttpResponseRedirect('/')
else:
form=commentForm()
template=loader.get_template('apple3/comment.html')
context=RequestContext(request,{
'form':form,
}
)
return HttpResponse(template.render(context))
每當我打開我的頁面上面的形式顯示如下錯誤:
Exception Type: AttributeError
Exception Value: 'function' object has no attribute 'objects'