urls.py
from django.conf.urls import url, include from . import views from rest_framework.routers import SimpleRouter router = SimpleRouter() # /books/image/(pk) 提交 form-data:用image携带图片,这的image要与反序列字段的image一致 router.register(‘books/image‘, views.BookUpdateImageAPIView, ‘book‘) urlpatterns = [ url(‘‘, include(router.urls)) ]
serializers.py
class BookUpdateImageModelSerializer(serializers.ModelSerializer): class Meta: model = models.Book fields = [‘image‘]
views.py
# 上传文件 - 修改头像 - 修改海报 from rest_framework.viewsets import GenericViewSet from rest_framework import mixins class BookUpdateImageAPIView(GenericViewSet, mixins.UpdateModelMixin): queryset = models.Book.objects.filter(is_delete=False).all() serializer_class = serializers.BookUpdateImageModelSerializer
原文地址:https://www.cnblogs.com/baohanblog/p/12354403.html
时间: 2024-11-09 00:41:05