摘要:
1 序列化组件介绍 1.序列化,序列化器会把模型对象转换成字典,经过response以后变成json字符串 2. 反序列化,把客户端发送过来的数据,经过request以后变成字典,序列化器可以把字典转成模型 3. 反序列化,完成数据校验功能 2 简单使用 1 写一个序列化的类,继承Serialize 阅读全文
摘要:
其实,反射就是通过字符串的形式,导入模块;通过字符串的形式,去模块寻找指定函数,并执行。利用字符串的形式去对象(模块)中操作(查找/获取/删除/添加)成员,一种基于字符串的事件驱动! 先来介绍四个内置函数: 1 getattr() getattr()函数是Python自省的核心函数,具体使用大体如下 阅读全文
摘要:
class Foo: x = 1 def __init__(self, y): self.y = y def __getattr__(self, item): print(' > from getattr:你找的属性不存在') def __setattr__(self, key, value): p 阅读全文
摘要:
url.py path("books/",views.BookView.as_view()), views.py from app01 import models from django.http import JsonResponse from rest_framework.views impor 阅读全文
摘要:
cbv源码 # ModelViewSet继承View(django原生View) # APIView继承了View # 先读View的源码 from django.views import View # urls.py path('books1/', views.Books.as_view( 阅读全文