Skip to content

Commit

Permalink
更新主页搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
xishandong committed Jul 12, 2023
1 parent f1ecd35 commit a72681e
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 14 deletions.
Binary file modified Server01/__pycache__/models.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Server01/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def delete(self, *args, **kwargs):
# 删除关联的帖子图片
self.imgs.all().delete()
# 删除帖子的图片的存储
path = SYSTEM_PATH + '/webServer/Server01/static/img/post/'
path = SYSTEM_PATH + 'post/'
check_and_delete(path, self.id)
# 删除帖子本身
super().delete(*args, **kwargs)
Expand Down
Binary file added Server01/static/img/avatar/10-lisa.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 removed Server01/static/img/avatar/10-金智秀.jpg
Binary file not shown.
Binary file added Server01/static/img/post/34-张娜英.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/views/__pycache__/post.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/views/__pycache__/user.cpython-39.pyc
Binary file not shown.
15 changes: 12 additions & 3 deletions Server01/views/post.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from django.db.models import Q
from django.http import JsonResponse

import Server01.models as models
Expand All @@ -12,7 +13,7 @@
def upload_post(request, payload):
file = request.FILES['file']
id = request.POST.get('id')
file_path = SYSTEM_PATH + '/webServer/Server01/static/img/post/' + str(id) + '-' + file.name
file_path = SYSTEM_PATH + 'post/' + str(id) + '-' + file.name
with open(file_path, 'wb') as destination:
for chunk in file.chunks():
destination.write(chunk)
Expand Down Expand Up @@ -71,15 +72,23 @@ def get_post_detail(request):
'createTime': convert_to_timezone(post.created_at, TIME_ZONE)
}
return JsonResponse({'info': info}, status=200)
return JsonResponse({'error': '错误的访问'}, status=401)
return JsonResponse({'error': '错误的访问'}, status=404)


# 主页推送帖子
def query_post_index(request):
data = json.loads(request.body)
offset = data['offset']
query = data.get('query')
limit = 20 # 每页显示的帖子数量
posts = models.Post.objects.all()
if query:
posts = models.Post.objects.filter(
Q(title__icontains=query) |
Q(user__username__icontains=query) |
Q(content__icontains=query)
)
else:
posts = models.Post.objects.all()
count = posts.count()

if 0 <= offset < count:
Expand Down
8 changes: 4 additions & 4 deletions Server01/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def query_user_index(request):
'favorites': list(combine_index_post(user.favorites.all()))
}
return JsonResponse({'data': info}, status=200)
return JsonResponse({'error': '错误的访问'}, status=401)
return JsonResponse({'error': '非法访问'}, status=401)
return JsonResponse({'error': '错误的访问'}, status=404)
return JsonResponse({'error': '非法访问'}, status=404)


# 获取用户关注用户id
Expand Down Expand Up @@ -120,8 +120,8 @@ def update_user_info(request, payload):
def update_avatar(request, payload):
file = request.FILES['file']
id = payload['user_id']
file_path = SYSTEM_PATH + '/webServer/Server01/static/img/avatar/' + str(id) + '-' + file.name
check_and_delete(id, SYSTEM_PATH + '/webServer/Server01/static/img/avatar/')
file_path = SYSTEM_PATH + 'avatar/' + str(id) + '-' + file.name
check_and_delete(id, SYSTEM_PATH + 'avatar/')
with open(file_path, 'wb') as destination:
for chunk in file.chunks():
destination.write(chunk)
Expand Down
Binary file modified webServer/__pycache__/settings.cpython-39.pyc
Binary file not shown.
10 changes: 4 additions & 6 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 @@ -126,6 +126,7 @@

CORS_ALLOWED_ORIGINS = [
'http://localhost:5173',
'http://127.0.0.1:5173'
]

CORS_ALLOWED_METHODS = [
Expand All @@ -138,11 +139,8 @@
'Content-Type',
]

# 启用 CSRF 保护
CSRF_COOKIE_HTTPONLY = True

# 配置保存文件路径
SYSTEM_PATH = 'D:/vue'
SYSTEM_PATH = 'D:/vue/webServer/Server01/static/img/'



0 comments on commit a72681e

Please sign in to comment.