{{{
urlpatterns = (
url(r'', include('.myapp.urls')),
)
}}}
.. becomes equivalent to::
{{{
urlpatterns = (
url(r'', include('myproject.myapp.urls')),
)
}}}
Whilst a contrived example, this can make heavy-nested apps look far, far
cleaner. For example, within `myproject.foo.foo_bar.foo_bar_baz.urls`, one
only needs to include `.foo_bar_baz_qux.urls` to get to the "next"
level, rather than the significantly more unwieldy
`myproject.foo.foo_bar.foo_bar_baz.foo.bar_baz_qux.urls`.
--
Ticket URL: <https://code.djangoproject.com/ticket/26288>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
PR here: https://github.com/django/django/pull/6212
--
Ticket URL: <https://code.djangoproject.com/ticket/26288#comment:1>
* stage: Unreviewed => Someday/Maybe
Comment:
I created a [https://groups.google.com/d/topic/django-developers/_li7KXow-
ps/discussion discussion on django-developers] to get feedback on the
idea.
--
Ticket URL: <https://code.djangoproject.com/ticket/26288#comment:2>
Comment (by timgraham):
Marten said on the mailing list, "the whole problem can already be fixed
from the user's perspective by importing the module instead of using
string based imports. That is possible and has been possible for a long
time. In that light, I don't see the benefit of supporting relative string
based imports with some confusing edge-cases."
Any problem with that approach?
--
Ticket URL: <https://code.djangoproject.com/ticket/26288#comment:3>
Comment (by lamby):
> Any problem with that approach?
Well, firstly it's extra stuff you have to explicitly import which seems a
style regression from the "oh just use these included urls" that you get
with the string-based import.
Secondly, whilst it might look fine when you are doing it once, for
example:
{{{
from django.conf.urls import url, include
from . import views
from .foo import urls
urlpatterns = (
url(r'', include(urls, namespace='foo')),
url(r'^$', views.landing, name='landing'),
)
}}}
.. but the import dance get a bit nasty when you have multiple ones - you
have to alias each import:
{{{
from django.conf.urls import url, include
from . import views
from .foo_app import urls as foo_urls
from .bar_app import urls as bar_urls
# etc.
urlpatterns = (
url(r'', include(foo_urls, namespace='foo')),
url(r'', include(bar_urls, namespace='bar')),
url(r'^$', views.landing, name='landing'),
)
}}}
This isn't an readabiliy improvement over using the string urls IMHO.
Now, if only we could do the following:
{{{
from . import views, foo_app, bar_app
urlpatterns = (
url(r'', include(foo_app.urls), namespace='foo')),
url(r'', include(bar_app.urls), namespace='bar')),
url(r'^$', views.landing, name='landing'),
)
}}}
:(
--
Ticket URL: <https://code.djangoproject.com/ticket/26288#comment:4>
Comment (by timgraham):
Perhaps you could add your view on the mailing list discussion? Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/26288#comment:5>
* status: new => closed
* resolution: => wontfix
Comment:
Closing due to lack of interest on the mailing list.
--
Ticket URL: <https://code.djangoproject.com/ticket/26288#comment:6>