在Django Rest框架选项请求中显示过滤器和排序

编程入门 行业动态 更新时间:2024-10-09 23:17:09
本文介绍了在Django Rest框架选项请求中显示过滤器和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Django Rest框架我注意到,在API的网络浏览部分有一个按钮,当它点击它显示以下...

I'm using the Django Rest Framework I noticed on the web browseable part of the API there is a button called 'options' when clicked it shows the following...

HTTP 200 OK Vary: Accept Content-Type: text/html Allow: HEAD, GET, OPTIONS { "parses": [ "application/json", "application/x-www-form-urlencoded", "multipart/form-data" ], "renders": [ "application/json", "text/html" ], "name": "Products", "description": "API endpoint." }

我的问题是,无论如何我可以在这里列出所有的过滤器选项

my question is, is there anyway I could list out here all the filter options an other stuff for this url?

推荐答案

您可以使选项返回无论你想要什么,通过覆盖视图上的 .metadata()方法。

You can make OPTIONS return whatever you want, by overriding the .metadata() method on the view.

参见这里: github/tomchristie/django-rest-框架/ blob / master / rest_framework / views.py#L340

截至2015年的更新:我们现在有一个可自定义的元数据API,使其更容易: http ://www.django-rest-framework/api-guide/metadata/

Update as of 2015: We now have a customizable metadata API that makes this easier: www.django-rest-framework/api-guide/metadata/

更多推荐

在Django Rest框架选项请求中显示过滤器和排序

本文发布于:2023-10-12 04:14:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   框架   选项   Django   Rest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!