Skip to content

Commit

Permalink
主评论功能完成
Browse files Browse the repository at this point in the history
  • Loading branch information
xishandong committed Jul 11, 2023
1 parent 0fc3c79 commit 5e48509
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 5 deletions.
Binary file added Server01/static/img/post/28-img3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Server01/util/__pycache__/verifyJWT.cpython-39.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions Server01/util/verifyJWT.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def wrapper(request, *args, **kwargs):
except jwt.InvalidTokenError:
error_message = {'error': '非法的token'}
return JsonResponse(error_message, status=401)
except AttributeError:
error_message = {'error': '非法的访问'}
except AttributeError as e:
error_message = {'error': str(e)}
return JsonResponse(error_message, status=401)

return wrapper
Expand Down
Binary file added Server01/views/__pycache__/comment.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/views/__pycache__/post.cpython-39.pyc
Binary file not shown.
15 changes: 15 additions & 0 deletions Server01/views/comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json

from django.http import JsonResponse
from Server01.util.verifyJWT import authenticate_request
from Server01.models import Comment


@authenticate_request
def do_comment(request, verify_payload):
data = json.loads(request.body)
print(verify_payload)
user_id = verify_payload['user_id']
data['user_id'] = user_id
comment = Comment.objects.create(**data)
return JsonResponse({'info': '评论已发送!', 'id': comment.id}, status=200)
14 changes: 13 additions & 1 deletion Server01/views/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@ def get_post_detail(request):
'title': post.title,
'id': post.id,
'imgs': [img.imagePath for img in imgs],
'comment': [],
'comment': [
{
'id': comment.id,
'content': comment.content,
'createTime': comment.created_at,
'user': {
'id': comment.user.id,
'username': comment.user.username,
'avatar': comment.user.avatar
}

} for comment in post.comments.all()
],
'user': {
'id': post.user.id,
'username': post.user.username,
Expand Down
Binary file modified webServer/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file modified webServer/__pycache__/urls.cpython-39.pyc
Binary file not shown.
5 changes: 3 additions & 2 deletions webServer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
from django.contrib import admin
from django.urls import path
from Server01.views import user, post
from Server01.views import user, post, comment

urlpatterns = [
path("admin/", admin.site.urls),
Expand All @@ -25,5 +25,6 @@
path('upload/', post.upload_post),
path('upload/info/', post.upload_post_info),
path('post/detail/', post.get_post_detail),
path('post/', post.query_post_index)
path('post/', post.query_post_index),
path('comment/', comment.do_comment)
]

0 comments on commit 5e48509

Please sign in to comment.