[Answer]-Can't make nestednamespaces what are the best practices for django urls

1👍

It seems you can go deeper because you’re finishing the regex with the dollar sign $. When this happens, Python recognizes that as the end of the expression and stop matching anything that follow, this can either yield a Url not found or some other page you didn’t requested.

Notice that every time they use include in the docs the regex doesn’t have the $ sign because normally you don’t want to end the expression there but in the included urls.

Your example may work without the $ signs like this:

urlpatterns_3rd_level = patterns('example.basket.views', url(r'^3rd$', 'home', name='home'))
urlpatterns_2nd_level = patterns('', url(r'^2nd', include(urlpatterns_3rd_level, namespace='basket')))

urlpatterns = patterns('', url(r'^1st', include(urlpatterns_2nd_level, namespace='store')))

reverse('store:basket:home') # No namespace named basket

Hint: Double check that example.basket.views is a valid module in your app because maybe the error may be that that module doesn’t exist.

From the shell I tested this and it yield:

>>> '/1st2nd3rd'

Hope this helps!

Leave a comment