tomchristie/django-rest-framework — pull request #2354 by rockymeza (2014-12-25 02:47:00+00:00)
Title: Add support for namespaces in APIRoot.

This pull request supercedes #2333, #2350 and is in response to #2351.

## Problem

The DefaultRouter API Root does not support namespaced URLs.

## How this PR attempts to resolve it

[@tomchristie recommended this](https://github.com/tomchristie/django-rest-framework/issues/2351#issuecomment-68061984)

> The API root view can inspect the incoming request, determine the namespace if there is one on the request object, and modify the view names accordingly if so.

So that's how this pull request attempts to resolve the issue.

## Things I'm not satisfied with about this PR

The implementation of `get_namespace` is more complicated than it should be, but only because it has to support tests in two ways:

1. The default Django request handlers add a resolver_match object to the request, but the tests don't provide that
2. Some tests send requests to the APIRoot using a fake request with the url `'/'`, which triggers a Resolver404.

Were it not for those two problems, the implementation would simply be `namespace = request.resolver_match.namespace`.

Thank you for your time and patience with this series of pull requests.