feat: 首页配置封面图上传预览,修复系列活动跳转,活动卡片样式优化
All checks were successful
Deploy to Server / deploy (push) Successful in 1m56s
All checks were successful
Deploy to Server / deploy (push) Successful in 1m56s
This commit is contained in:
@@ -14,14 +14,24 @@ from .serializers import (
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@api_view(['GET', 'PATCH'])
|
||||
@permission_classes([permissions.AllowAny])
|
||||
def get_homepage_config(request):
|
||||
"""获取首页配置"""
|
||||
"""获取或更新首页配置(PATCH 支持 multipart/form-data 上传图片)"""
|
||||
try:
|
||||
config = HomePageConfig.objects.filter(is_active=True).first()
|
||||
if not config:
|
||||
config = HomePageConfig.objects.create()
|
||||
|
||||
if request.method == 'PATCH':
|
||||
serializer = HomePageConfigSerializer(
|
||||
config, data=request.data, partial=True, context={'request': request}
|
||||
)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response(serializer.data)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
serializer = HomePageConfigSerializer(config, context={'request': request})
|
||||
return Response(serializer.data)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user