在旧的 django rest swagger 中,可以paramType: form在 viewset 的 docstring 中指定,并通过 获取参数request.data['param_x'],如下:
class FooViewSet(viewsets.ViewSet):
"""
Make something cool
---
parameters:
- name: param_x
required: true
paramType: form
"""
def list(self, request):
param_x = request.data['param_x']
# do something cool...
在较新的版本中,我通常使用coreapi.Field指定参数的属性,并将参数类型设置为location参数键(例如core.api.Field(name='param_x', location='query'))。文档中讨论了所有可用的位置值。然而,他们似乎都没有按照我的预期去做(甚至没有location='form')。
如何form使用较新版本的 django rest swagger 设置参数类型?我可能在这里遗漏了一些东西。