I have a parent URLconf:
from django.conf.urls import include, patterns, url
urlpatterns = patterns('',
(r'^main/(?P<name>[^/]+)/(?P<region>[^/]+)/(?P<id>[^/]+)/', include('foo')),
)
And a child URLconf (included in the parent) that includes a redirect:
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^view/$', RedirectView.as_view(url='/main/%(name)s/%(region)s/%(id)s/detail')),
)
(Essentially, I'm trying to redirect a path that looks like /main/product/1/134/view
to a path that looks like /main/product/1/134/detail
.)
The Django documentation says that "An included URLconf receives any captured parameters from parent URLconfs."
But when I try access /main/product/1/134/view
, I get a KeyError
because name
isn't recognized.
Is there some other way that I have to reference the received captured parameters in the RedirectView?
Note: I don't get an error when I do the whole thing in the parent URLconf:
urlpatterns = patterns('',
(r'^main/(?P<name>[^/]+)/(?P<region>[^/]+)/(?P<id>[^/]+)/view/$', RedirectView.as_view(url='/main/%(name)s/%(region)s/%(id)s/detail'))
)