def comment(request):
form = CommentForm(request.POST)
if form.is_valid():
comment = Comment()
comment.content = form.cleaned_data.get('content')
comment.user = request.user
id=form.cleaned_data.get('article_id')
try:
article = Article.objects.get(id=id)
comment.article = article
comment.save()
article.save()
rtn = {'status':True,'redirect':reverse('blog:show', args=[id])}
except Article.DoesNotExist:
rtn = {'status':False,'error':'Article is not exist'}
else:
rtn = {'status':False,'error':form.errors}
return JsonResponse(rtn)
评论列表
文章目录