码迷,mamicode.com
首页 > Web开发 > 详细

上传文件接口

时间:2020-02-23 22:06:50      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:djang   mode   序列   orm   conf   sim   work   object   gem   

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

 

上传文件接口

标签:djang   mode   序列   orm   conf   sim   work   object   gem   

原文地址:https://www.cnblogs.com/baohanblog/p/12354403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!