当前位置:网站首页>Drf--- quick start 01
Drf--- quick start 01
2022-07-03 04:15:00 【I'm not big head】
# todo To be sorted out
One . Introduction to serialization components
0. The model object is querySet
1. serialize : The serializer converts the model object into a dictionary , after response Later it became json character string
2. Deserialization : Send the data from the client , after request Later it became a dictionary , The serializer can turn the dictionary into a model
3. Deserialization : Complete data verification function
Two . Quick to use
# urls.py
re_path('books/(?P<pk>\d+)', views.BookView.as_view()),
# views.py
class BookView(APIView):
def get(self,request,pk):
book=Book.objects.filter(id=pk).first()
# With a class , without doubt , Be sure to instantiate
# Who do you want to serialize , Just pass someone over
book_ser=BookSerializer(book) # The calling class __init__
# book_ser.data Serializing objects .data It's the dictionary after serialization
return Response(book_ser.data)
******* The serializer is in charge of itself , Which field do you want to serialize , Just write that
# ser.py
class BookSerializer(serializers.Serializer):
# id=serializers.CharField()
name=serializers.CharField()
# price=serializers.DecimalField()
price=serializers.CharField()
author=serializers.CharField()
publish=serializers.CharField()
边栏推荐
- [brush questions] find the number pair distance with the smallest K
- Mutex and rwmutex in golang
- Which code editor is easy to use? Code editing software recommendation
- Deep dive kotlin synergy (20): build flow
- 基于Pytorch和RDKit的QSAR模型建立脚本
- Wechat applet + Alibaba IOT platform + Hezhou air724ug built with server version system analysis
- [文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
- What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
- Bisher - based on SSM pet adoption center
- [set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
猜你喜欢
竞品分析撰写
Daily question - ugly number
Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
Which code editor is easy to use? Code editing software recommendation
The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
Basic MySQL operations
JS realizes the animation effect of text and pictures in the visual area
Database management tool, querious direct download
Data Lake three swordsmen -- comparative analysis of delta, Hudi and iceberg
随机推荐
eth入门之DAPP
Taking two column waterfall flow as an example, how should we build an array of each column
Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
[mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
How to download pytorch? Where can I download pytorch?
Introduction to eth
【毕业季·进击的技术er】职场人的自白
[set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
Feature_selection
What can learning pytorch do?
sklearn数据预处理
Supervised pre training! Another exploration of text generation!
QSAR model establishment script based on pytoch and rdkit
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
[set theory] set concept and relationship (set family | set family examples | multiple sets)
[Apple Photo Album push] IMessage group anchor local push
[set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
nodejs基础:浅聊url和querystring模块
国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来