In Django RestFramework, how to change the Api Root documentation?

后端 未结 6 1544
遇见更好的自我
遇见更好的自我 2021-02-04 02:12

In django RestFramework, is there any \"official\" way to generate the documentation for the \"Api Root\" ?

After looking at the RestFramework\'s source code, I\'ve foun

6条回答
  •  青春惊慌失措
    2021-02-04 03:05

    I'm new to this but I found you can use a SimpleRouter instead of a DefaultRouter to specify your own APIRoot.

    in urls.py in your api module

    from django.conf.urls import patterns, url, include
    from rest_framework.routers import SimpleRouter
    router = SimpleRouter()
    
    urlpatterns = patterns('api.views',
        url(r'^$', views.APIRoot.as_view()),
        url(r'', include(router.urls)),
    )
    

    Then specify the documentation in the class comment

    from rest_framework import generics
    
    class APIRoot(generics.GenericAPIView):
        """
        My API documentation
        """
    

提交回复
热议问题