我正在使用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框架选项请求中显示过滤器和排序
发布评论