在Swagger中添加GET参数

时间:2018-02-08 09:46:42

标签: django django-rest-framework swagger-ui django-rest-swagger

在未显示可用GET参数的方法文档中使用django rest frameworkdjango-rest-swagger,问题是如何设置?

代码:

# views.py
@api_view(['GET'])
def tests_api(request):
    """

    :param request:
    :return:
    """
    id = request.query_params.get('id')
    name = request.query_params.get('name')

    return Response({'user': name, 'text': 'Hello world'})

# urls.py
urlpatterns = [
    url(r"^api/v1/tests_api/$", tests_api),
]

http api:

GET https://127.0.0.1/api/v1/tests_api/?name=Denis&id=3

HTTP/1.1 200 OK
...
{
    "user": "Denis",
    "text": "Hello world"
}

现在: enter image description here 例: enter image description here

Russian版。

1 个答案:

答案 0 :(得分:-2)

    urlpatterns = [
    url(r'^api/v1/tests_api/(?P<id>\d+)/(?P<name>\w+)/$', tests_api),

]

enter image description here