Open ghost opened 8 years ago
def get_api_root_view(self): """ Return a view to use as the API root. """ api_root_dict = OrderedDict() list_name = self.routes[0].name for prefix, viewset, basename in self.registry: api_root_dict[prefix] = list_name.format(basename=basename)
class APIRoot(views.APIView):
_ignore_model_permissions = True
def get(self, request, format=None, *args, **kwargs):
ret = OrderedDict()
namespace = request.resolver_match.namespace
for key, url_name in api_root_dict.items():
import re
match = re.search(r'parent_lookup_\w+', key)
if match:
k = match.group()
kwargs[k] = k.split("parent_lookup_")[-1]
kwargs[k] = 1
if namespace:
url_name = namespace + ':' + url_name
try:
ret[key] = reverse(
url_name,
args=args,
kwargs=kwargs,
request=request,
format=kwargs.get('format', None)
)
except NoReverseMatch:
pass
return Response(ret)
return APIRoot.as_view()
the response of the route api-root is '{}'