我尝试了很多但找不到解决方案 我也尝试了 javascript 但找不到解决方案
def postPage(request, id):
post = Post.objects.get(pk=id)
showcomment = Comment.objects.filter(postby = id)
form = commentForm()
form = commentForm(request.POST)
form.instance.postby = post
if form.is_valid():
form.save()
form = commentForm()
redirect('postpage', id=post.sno)
context = {'post':post, 'form':form, 'showcomment':showcomment}
return render(request, 'blog/postpage.html', context)
form = commentForm() 只有字段显示空白 但是我们刷新时提交数据
HTML 文件
form action="." method="POST">
{{form}}
{% csrf_token %}
<input type="submit">
</form>