3 回答

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超7個(gè)贊
你的錯(cuò)誤在模板中。name
您的輸入之一設(shè)置錯(cuò)誤:
在你的代碼中:
<input type="hidden" name = "comment" value = "{{post.sno}}">
正確版本:
<input type="hidden" name = "postSno" value = "{{post.sno}}">

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
為了解決您的第一個(gè)問題,您應(yīng)該將該行post = Post.objects.get(sno=postSno)(在postComment函數(shù)中)更改為:
from django.http import Http404
try:
post = Post.objects.get(sno=postSno)
except Post.DoesNotExist:
return Http404("Post does not exist") # or return HttpResponse("Post does not exist")
因?yàn)樵谀承┣闆r下該查詢可能無法返回任何結(jié)果,因此會(huì)引發(fā)DoesNotExistError。第二個(gè)問題(我的意思是NameError at /blog/postComment name 'comments' is not defined)來自相同的函數(shù)...更改此行將comment = BlogComment(comment=comments, user=user, post=post)解決comment = BlogComment(comment=comment or '', user=user, post=post)此問題。
添加回答
舉報(bào)