[Django] #26288: Support relative imports in django.conf.urls.include

4 views
Skip to first unread message

Django

unread,
Feb 27, 2016, 10:58:11 AM2/27/16
to django-...@googlegroups.com
#26288: Support relative imports in django.conf.urls.include
-----------------------------+--------------------
Reporter: lamby | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Keywords: urls
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
For example, within `myproject.urls`:

{{{
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.

Django

unread,
Feb 27, 2016, 10:58:43 AM2/27/16
to django-...@googlegroups.com
#26288: Support relative imports in django.conf.urls.include
-----------------------------+--------------------------------------

Reporter: lamby | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:

Keywords: urls | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by lamby):

* 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>

Django

unread,
Feb 29, 2016, 8:56:07 AM2/29/16
to django-...@googlegroups.com
#26288: Support relative imports in django.conf.urls.include
-----------------------------+-----------------------------------------

Reporter: lamby | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: urls | Triage Stage: Someday/Maybe

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Mar 2, 2016, 9:32:57 AM3/2/16
to django-...@googlegroups.com
#26288: Support relative imports in django.conf.urls.include
-----------------------------+-----------------------------------------

Reporter: lamby | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: urls | Triage Stage: Someday/Maybe
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-----------------------------------------

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>

Django

unread,
Mar 2, 2016, 10:01:10 AM3/2/16
to django-...@googlegroups.com
#26288: Support relative imports in django.conf.urls.include
-----------------------------+-----------------------------------------

Reporter: lamby | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: urls | Triage Stage: Someday/Maybe
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-----------------------------------------

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>

Django

unread,
Mar 2, 2016, 10:24:57 AM3/2/16
to django-...@googlegroups.com
#26288: Support relative imports in django.conf.urls.include
-----------------------------+-----------------------------------------

Reporter: lamby | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: urls | Triage Stage: Someday/Maybe
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-----------------------------------------

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>

Django

unread,
May 7, 2016, 5:27:04 PM5/7/16
to django-...@googlegroups.com
#26288: Support relative imports in django.conf.urls.include
-----------------------------+-----------------------------------------
Reporter: lamby | Owner: nobody
Type: New feature | Status: closed

Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution: wontfix

Keywords: urls | Triage Stage: Someday/Maybe
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-----------------------------------------
Changes (by timgraham):

* 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>

Reply all
Reply to author
Forward
0 new messages