标签:djang mode 序列 orm conf sim work object gem
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)) ]
class BookUpdateImageModelSerializer(serializers.ModelSerializer): class Meta: model = models.Book fields = [‘image‘]
# 上传文件 - 修改头像 - 修改海报 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
标签:djang mode 序列 orm conf sim work object gem
原文地址:https://www.cnblogs.com/baohanblog/p/12354403.html