提交评论功能
This commit is contained in:
@@ -2,6 +2,7 @@ from django import http
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib.auth.backends import ModelBackend # 验证基类
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from rest_framework.views import APIView
|
||||
@@ -190,3 +191,19 @@ def come_kecheng(request):
|
||||
return http.JsonResponse({'code': CODE_SUCCESS, 'msg': '发布成功'})
|
||||
|
||||
|
||||
def comment_control(request): # 提交评论的处理函数
|
||||
comment_content = request.POST.get('comment_content')
|
||||
article_id = request.POST.get('article_id')
|
||||
pid = request.POST.get('pid')
|
||||
id = MindUser.objects.get(username=request.user.username).id
|
||||
author_id = id # 获取当前用户的ID
|
||||
Comment.objects.create(comment_content=comment_content, pre_comment_id=pid, pinglun_id=article_id,
|
||||
user_id=author_id) # 将提交的数据保存到数据库中
|
||||
|
||||
article = list(
|
||||
Comment.objects.values('id', 'comment_content', 'pre_comment_id', 'pinglun_id', 'user_id',
|
||||
'comment_time')) # 以键值对的形式取出评论对象,并且转化为列表list类型
|
||||
|
||||
return JsonResponse(article, safe=False) # JsonResponse返回JSON字符串,自动序列化,如果不是字典类型,则需要添加safe参数为False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user