django序列化器嵌套
介绍 (Introduction)
The article introduces how to use DRF-Nested-Routers framework https://github.com/alanjds/drf-nested-routers to create URLs for nested resources. In this tutorial, our target is to create APIs for getting libraries and books.
本文介绍了如何使用DRF-Nested-Routers框架https://github.com/alanjds/drf-nested-routers来为嵌套资源创建URL。 在本教程中,我们的目标是创建用于获取库和书籍的API。
/api/libraries/ -> Get list of libraries
/api/libraries/{library_id}/books/ -> Get list of book in a library
/api/libraries/{library_id}/books/{book_id} -> Get details of a book
图表 (Diagram)
![Image for post](https://miro.medium.com/max/9999/1*OQF-OMC2gu-WttNkdNTKUg.png)
问题 (Problem)
Django Rest Framework supports to generate the URL by using Routers.
Django Rest Framework支持使用路由器生成URL。
REST framework adds support for