restframeword之视图,解析器
Posted maojiang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了restframeword之视图,解析器相关的知识,希望对你有一定的参考价值。
最终版本 五个方法封装
位置参数 看源码
视图四个方法:
视图
(1) (常用)
class AuthorSerializers(serializers.ModelSerializer): class Meta: model=Author fields="__all__" class AuthorView(APIView): def get(): pass def post(): pass class AuthorDetailView(APIView): def get(): pass def delete(): pass def put(): pass
from rest_framework.mixins import CreateModelMixin,ListModelMixin,DestroyModelMixin,RetrieveModelMixin,UpdateModelMixin
from rest_framework import generics
(2) class AuthorView(CreateModelMixin,ListModelMixin,generics.GenericAPIView,):
queryset=Author.objects.all serializer_class=AuthorSerializers def get(self,request): return self.list(request) def post(self,request): return self.create(request) class AuthorDetailView(DestroyModelMixin,UpdateModelMixin,RetrieveModelMixin,generics.GenericAPIView,): queryset = Author.objects.all serializer_class = AuthorSerializers def get(self,request, *args, **kwargs): return self.retrieve(request, *args, **kwargs) def put(self,request, *args, **kwargs): return self.update(request, *args, **kwargs) def delete(self,request, *args, **kwargs): return self.destroy(request, *args, **kwargs)
(3) class AuthorView(generics.ListCreateAPIView):
class AuthorView(generics.ListCreateAPIView): queryset=Author.objects.all serializer_class=AuthorSerializers class AuthorDetailView(generics.RetrieveUpdateDestroyAPIView): queryset = Author.objects.all serializer_class = AuthorSerializers
from rest_framework.viewsets import ModelViewSet
(4) class AuthorModelView(ModelViewSet):(常用)
class AuthorModelView(ModelViewSet) queryset=Author.objects.all() serializer_class=AuthorSerializers
解析器
如果一个属性点一个没有的属性
就会执行这个
可以定义全局
解析器是什么时候执行,request.data
解析器
class APIView:
parser_classes = api_settings.DEFAULT_PARSER_CLASSES
以上是关于restframeword之视图,解析器的主要内容,如果未能解决你的问题,请参考以下文章
Android 逆向使用 Python 解析 ELF 文件 ( Capstone 反汇编 ELF 文件中的机器码数据 | 创建反汇编解析器实例对象 | 设置汇编解析器显示细节 )(代码片段
restful 和 restframeword 和 restframeword 序列化