在Django Rest框架选项请求中显示过滤器和排序 [英] Show Filters and Ordering in Django Rest Framework Options Request

查看:270
本文介绍了在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.

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

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

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

这篇关于在Django Rest框架选项请求中显示过滤器和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆