views.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:django-blog 作者: luckybirdme 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号