简体   繁体   中英

How to change DRF to use a Response from a schema?

Is it possible to change the Django Rest Framework to use a Response from a schema?

For example, a GET using the standard DRF will output:

{
  "count": 0,
  "next": null,
  "previous": null,
  "results": []
}

Where I would like it to output

{
  "meta_stuff": {
    "License": "MIT"
    },
  "data": []
 }

Where results = data and an extra ). Would I need to customise DRF or can a swagger.JSON schema be used to achieve this?

I suppose you're talking about pagination style. If so you should look at this link: http://www.django-rest-framework.org/api-guide/pagination/#custom-pagination-styles .

Basically you're going to write your own custom Pagination class, customizing DRF's behavior. Documentation's example is exactly what you've described.

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