Closed
Description
Out of the box, DRF is not able to reverse view-names given the following routing:
In the project's urls.py:
urlpatterns = pattern(
'',
url(r'^(?P<slug>\w+)/api/app/', include('app.urls'))
)
in the app's urls.py:
router = routers.SimpleRouter()
router.register(r'items', views.ItemViewSet)
urlpatterns = pattern(
'',
url(r'^', include(router.urls)),
)
This will raise NoReverseMatch
exceptions, because the get_url
implementations of HyperlinkedIdentityField
and HyperlinkedRelatedField
ignore the slug
captured parameter.
Currently, there's a hacky way to subclass the Hyperlinked*Field
classes, and get at the view's kwargs via request.parser_context['kwargs']
.
The captured parameters are available to the HyperlinkedModelSerializer
through self.context['view'].kwargs
, maybe it would be better if those kwargs were provided to the appropriate Hyperlinked*Field
instances ?