ModelForm不保存数据

时间:2014-03-17 16:21:57

标签: django

它没有保存数据:

# Models

class Comment(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    author = models.CharField(max_length=60)
    body = models.TextField()

# Forms   

class CommentForm(ModelForm):
        class Meta:
            model = Comment

#Views.py

def add_comment(request):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            save_it = form.save()
            save_it.save()
            comment = form.cleaned_data["body"]
        return render(request, 'task-result.html', {
        'form': form, 'comment': comment,
        })
    else:
        form = CommentForm()
        return render(request, 'Task-form.html', {
        'form': form,
        })

如您所见,我不仅试图将评论的数据保存到数据库中,而且还将其打印出来。那我的错误在哪里?

0 个答案:

没有答案