5

Use django rest framework and django-rest-swagger in documentation of the methods it is not showing available GET parameters and the question is how can I set?

code:

# 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"
}

now: enter image description here example: enter image description here

Russian version.

devnull
  • 393
  • 4
  • 20

2 Answers2

0

Declare schema manually and specify fields there with location query

  schema = ManualSchema(fields=[
        coreapi.Field(
            "name",
            required=True,
            location="query",
            schema=coreschema.String()
        ),
    ]
  )

See doc for details

fo2rist
  • 1,903
  • 15
  • 22
-2
    urlpatterns = [
    url(r'^api/v1/tests_api/(?P<id>\d+)/(?P<name>\w+)/$', tests_api),

]

enter image description here