第 4 章 API 中的排序
为了让您易于使用,我们在整个指南中使用以下 URL:
https://<server name>/api/v2/groups/
流程
要指定 {{ model_verbose_name_plural }} 以特定顺序返回,请使用
GET
请求上的order_by
查询字符串参数:https://<server name>/api/v2/model_verbose_name_plural?order_by={{ order_field }}
为字段名称加上短划线(
-
)前缀,以反向排序:https://<server name>/api/v2/model_verbose_name_plural?order_by=-{{ order_field }}
您可以使用逗号分隔字段名称(、
、
)来指定排序字段:https://<server name>/api/v2/model_verbose_name_plural?order_by={{ order_field }},some_other_field