#url.py
from django.contrib import admin
from django.urls import path, re_path
from app_drf_books import views
urlpatterns = [
path('admin/', admin.site.urls),
path('books/', views.BooksAPIView.as_view()),
re_path('books/(?P<pk>\d+)', views.BookAPIView.as_view())
]
#utils.py 自定义工具类
class MyResponse():
def __init__(self):
self.code = 100
self.msg = 'OK'
@property
def dict(self):
return self.__dict__
#模型类models.py
from django.db import models
# Create your models here.
class Books(models.Model):
title = models.CharField(max_length=32)
price = models.DecimalField(max_digits=5, decimal_places=2)
author = models.CharField(max_length=32
python drf 序列化器之数据的增删改查(详细)基于APIView
最新推荐文章于 2024-04-29 23:44:03 发布
本文详细介绍了如何使用Python Django Rest Framework(DRF)的序列化器进行数据的创建、读取、更新和删除操作,基于APIView实现。通过实例解析,深入理解DRF序列化器在API开发中的应用。
摘要由CSDN通过智能技术生成