简体   繁体   中英

how to access serialized data in django rest framework

I have this data in my serializer

EditScheduleSerializerByDate(data={'time1': '09:00:00', 't1course1': 'Machine Learning'}, initial={'ss': <QuerySet [<Schedule: 2021-02-27 13:00:00 Machine Learning >, <Schedule: 2021-02-27 13:00:00 Deep Learning >, <Schedule: 2021-02-27 14:00:00 Deep Learning >]>})

I am unable to access data using serializer.data but I am able to access serializer.initial

It is giving empty list in serializer.data

You should call .is_valid() method before accessing serializer.data :

if serializer.is_valid():
    # Now you can get serializer.data

Or you can call initial_data to access data before calling is_valid() method:

print(serializer.initial_data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM