Nested includes and captured parameters

11 views
Skip to first unread message

Jason Mayfield

unread,
Oct 9, 2013, 2:41:45 PM10/9/13
to django...@googlegroups.com
The docs state that "An included URLconf receives any captured parameters from parent URLconfs".  And that does work as expected, when the child URLconf makes immediate use of the parameter -- that is, the child URLconf is a terminal node and doesn't include any further child URLconfs.

In my particular use-case, I find myself needing to use two levels of URLconf includes, and when I do this, the captured parameter seems to get lost along the way.

Examples:

a)  In this scenario, "my_view" gets app1_pk passed in kwargs (expected behavior).

root urls.py:
    …
    url(r'^app1/(?P<app1_pk>\d+)/app2/', include('app2.urls')),
    …

    …
    url(r'^my_view/$', 'app2.views.my_view'),
    …

b)  In this scenario (my use-case), "my_view" does not get app1_pk passed in kwargs (but I do not expect this to be the correct behavior).

root urls.py:
    …
    url(r'^app1/', include('app1.urls')),
    …

    …
    url(r'^(?P<app1_pk>\d+)/app2/', include('app2.urls')),
    …

    …
    url(r'^my_view/$', 'app2.views.my_view'),
    …

Is this expected behavior?  Any thoughts?

Thanks in advance,
Jason

Jason Mayfield

unread,
Oct 9, 2013, 4:17:48 PM10/9/13
to django...@googlegroups.com
Nevermind.  Discovered typo in a URLconf regex that was causing the problem.
Reply all
Reply to author
Forward
0 new messages