摘要: drf自动生成路由一共分为五个步骤,导入路由类,实例化得到对象,注册路由,添加前缀,将自动生成的路由添加到urlpatterns中。 # 导入路由类 from rest_framework.routers import SimpleRouter, DefaultRouter # 实例化得到对象 ro 阅读全文
posted @ 2022-03-30 13:05 recordlife 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 1.普通版本的Response封装 新建一个response的文件夹 在新建的文件中写入封装的自定义的Response对象 class MyResponse(): def __init__(self): self.status = 100 self.msg = None @property def 阅读全文
posted @ 2022-03-30 10:50 recordlife 阅读(126) 评论(1) 推荐(0) 编辑
摘要: 1.配置响应格式 配置文件中配置(全局配置) REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( # 默认响应渲染类 'rest_framework.renderers.JSONRenderer', # json渲染器 'rest_framework.r 阅读全文
posted @ 2022-03-30 09:53 recordlife 阅读(90) 评论(0) 推荐(0) 编辑