Innovate anywhere, anytime Your cloud-based dev studio.

How to Document API Requests using Django Rest Swagger


In Developing an application, we'll write our required API's. To Document these API's we use Django Rest Swagger.

Django Rest Swagger is used to provide Documentation for all API's which are used in your application with brief description about each API individually.

It is Open Source so you can contribute to the project.

If your API's available to the users with description, so UI developers can understand and test your API's and use it accordingly.

First we need to install the swagger.

pip install django-rest-swagger

Add "rest_framework_swagger" to Django settings INSTALLED_APPS





Include the rest_framework_swagger URLs to a path of your choice

patterns = ('',


    url(r'^docs/$', schema_view, name="schema_view"),


In your API Views

from rest_framework.decorators import api_view, permission_classes, renderer_classes

from rest_framework.permissions import AllowAny

from rest_framework_swagger.renderers import OpenAPIRenderer, SwaggerUIRenderer


@permission_classes((AllowAny, ))

@renderer_classes([OpenAPIRenderer, SwaggerUIRenderer])

def schema_view(request):

    generator = schemas.SchemaGenerator(title='Rest Swagger')

    return Response(generator.get_schema(request=request))

If you are not authorized, This document List all the API which doesnt reguire any permission to get authorize.

If you want to use Rest Swagger in your application to authorize user, include below settings in your file. By this you will be provide with Authorize Button in the header when user hits the swagger document URL, When you click on it you will be prompt with a pop-up to enter details of Api key authorization. By providing your API Key the user gets Authorize.


    'USE_SESSION_AUTH': False,

    'api_version': '0.1',

    'enabled_methods': [





        "api_key": {

            "type": "apiKey",

            "name": "Authorization",

               "in": "header"