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
Thanks to frost-nzcr4's comment above, I found a nice way to do this:
from rest_framework import routers
from django.utils.safestring import mark_safe
class MyAPIRootView(routers.APIRootView):
"""
Controls appearance of the API root view
"""
def get_view_name(self) -> str:
return "My API"
def get_view_description(self, html=False) -> str:
text = "My REST API"
if html:
return mark_safe(f"{text}
")
else:
return text
class MyRouter(routers.DefaultRouter):
APIRootView = MyAPIRootView
Then use this router in your urls.py
:
router = MyRouter()