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 5e48509 commit dd96a0d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 11 deletions.
Binary file modified Server01/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions Server01/util/auxiliaryFuction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytz


def convert_to_timezone(datetime_obj, timezone_str):
target_timezone = pytz.timezone(timezone_str)
converted_datetime = datetime_obj.astimezone(target_timezone)
return converted_datetime.strftime('%Y-%m-%d %H:%M')
Binary file modified 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.
6 changes: 3 additions & 3 deletions Server01/views/comment.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import json

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

from Server01.models import Comment
from Server01.util.verifyJWT import authenticate_request


@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)
return JsonResponse({'info': '评论已发送!', 'id': comment.id}, status=200)
8 changes: 4 additions & 4 deletions Server01/views/post.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json

from django.http import JsonResponse

from webServer.settings import TIME_ZONE
import Server01.models as models
from Server01.util.verifyJWT import authenticate_request
from Server01.util.auxiliaryFuction import convert_to_timezone

system = 'D:/vue'

Expand All @@ -12,7 +13,6 @@ def upload_post(request):
file = request.FILES['file']
id = request.POST.get('id')
file_path = system + '/webServer/Server01/static/img/post/' + str(id) + '-' + file.name
print(id, file_path)
with open(file_path, 'wb') as destination:
for chunk in file.chunks():
destination.write(chunk)
Expand Down Expand Up @@ -52,7 +52,7 @@ def get_post_detail(request):
{
'id': comment.id,
'content': comment.content,
'createTime': comment.created_at,
'createTime': convert_to_timezone(comment.created_at, TIME_ZONE),
'user': {
'id': comment.user.id,
'username': comment.user.username,
Expand All @@ -66,7 +66,7 @@ def get_post_detail(request):
'username': post.user.username,
'avatar': post.user.avatar
},
'createTime': post.created_at
'createTime': convert_to_timezone(post.created_at, TIME_ZONE)
}
return JsonResponse({'info': info}, status=200)
return JsonResponse({'error': '错误的访问'}, status=401)
Expand Down
Binary file modified webServer/__pycache__/settings.cpython-39.pyc
Binary file not shown.
7 changes: 3 additions & 4 deletions webServer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
'ENGINE': 'django.db.backends.mysql',
'NAME': 'server01',
'USER': 'root',
'PASSWORD': '******',
'HOST': '******',
'PASSWORD': '!d0x9sDXS',
'HOST': '113.125.109.60',
'PORT': '3306',
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@

LANGUAGE_CODE = "zh-hans"

TIME_ZONE = "UTC"
TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

Expand Down Expand Up @@ -145,4 +145,3 @@




0 comments on commit dd96a0d

Please sign in to comment.