Allow namespaced reusable app urls as ROOT_URLCONF

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Allow namespaced reusable app urls as ROOT_URLCONF

Vlastimil Zíma-2
Hi,

I've tried to understand how to write an urls module for reusable app and I think I have it correctly:

# myapp.urls
app_name
= 'myapp'
urlpatterns
= [
    url
(r'^index/$', MyIndexView.as_view(), name='index'),
    url
(r'^form/$', MyFormView.as_view(), name='form'),
   
...
]


In code I use the reverses in form 'myapp:index' and 'myapp:form'. The problem is, that these urls may be the only one used by the Django project, hence I expected ROOT_URLCONF = 'myapp.urls' should work as well. But such shortcut ends up in "'myapp' is not a registered namespace" error. To avoid that, one needs to add another urls module only to include the `myapp.urls`, which seems unnecessary.

Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

Regards,
Vlastimil

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/784f0a1d-2677-4246-b713-23482c61c02b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Allow namespaced reusable app urls as ROOT_URLCONF

Florian Apolloner
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/f018ba7b-7bb6-43ce-8ec0-3cc02010c7e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Allow namespaced reusable app urls as ROOT_URLCONF

Tim Graham-2
The issue was raised some months ago in https://code.djangoproject.com/ticket/28413 and came to a similar conclusion. The resolution was to document the restriction.

On Thursday, February 15, 2018 at 10:57:54 AM UTC-5, Florian Apolloner wrote:
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/e7ece3c7-f46d-40c5-b619-df3c991b8e61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Allow namespaced reusable app urls as ROOT_URLCONF

Vlastimil Zíma-2
Based on the discussions I've seen, it looks like the problem is not looked at from the correct angle. The request is not to namespace the ROOT_URLCONF, but to respect namespace if a ROOT_URLCONF has one. The use case is to prevent creation of one extra file, just to include the only application urls. It would come handy in testing and deploying a single-application projects. It may also promote a correct usage of namespaces in application urls, since it would remove the need to construct extra urlconf module for the application tests.

Imagine having the application as defined in my first email. If I want to test it, I can't just use `@override_settings(ROOT_URLCONF='myapp.urls')`, I have to create single line urls.py for the tests, just to have the include which would not ignore the namespace. In my opinion, this commonly leads to just removing the namespace from the application URLs, which makes the problem apparently go away.

The #28413 also resulted in somewhat questionable output with no change at all. Apparently that wasn't good call, since this problem keeps recurring.

I suggest to do one of these things:
 * Take the ROOT_URLCONF namespace into account if it have any.
 * Document that ROOT_URLCONF can't have namespace AND provide a warning through Django system check framework.

Personally, I'd go for the first option, which I think has negligible impact on the performance and may promote a correct usage of the URL namespaces in third party applications.

Regards
Vlastimil

Dne čtvrtek 15. února 2018 18:03:44 UTC+1 Tim Graham napsal(a):
The issue was raised some months ago in <a href="https://code.djangoproject.com/ticket/28413" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;">https://code.djangoproject.com/ticket/28413 and came to a similar conclusion. The resolution was to document the restriction.

On Thursday, February 15, 2018 at 10:57:54 AM UTC-5, Florian Apolloner wrote:
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

Dne čtvrtek 15. února 2018 18:03:44 UTC+1 Tim Graham napsal(a):
The issue was raised some months ago in <a href="https://code.djangoproject.com/ticket/28413" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;">https://code.djangoproject.com/ticket/28413 and came to a similar conclusion. The resolution was to document the restriction.

On Thursday, February 15, 2018 at 10:57:54 AM UTC-5, Florian Apolloner wrote:
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

Dne čtvrtek 15. února 2018 18:03:44 UTC+1 Tim Graham napsal(a):
The issue was raised some months ago in <a href="https://code.djangoproject.com/ticket/28413" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;">https://code.djangoproject.com/ticket/28413 and came to a similar conclusion. The resolution was to document the restriction.

On Thursday, February 15, 2018 at 10:57:54 AM UTC-5, Florian Apolloner wrote:
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/2d6e757d-0c3f-4859-9c94-6f029022fb7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Allow namespaced reusable app urls as ROOT_URLCONF

Tim Graham-2
Feel free to reopen the ticket if you want to provide a patch.

On Friday, February 16, 2018 at 9:08:33 AM UTC-5, Vlastimil Zíma wrote:
Based on the discussions I've seen, it looks like the problem is not looked at from the correct angle. The request is not to namespace the ROOT_URLCONF, but to respect namespace if a ROOT_URLCONF has one. The use case is to prevent creation of one extra file, just to include the only application urls. It would come handy in testing and deploying a single-application projects. It may also promote a correct usage of namespaces in application urls, since it would remove the need to construct extra urlconf module for the application tests.

Imagine having the application as defined in my first email. If I want to test it, I can't just use `@override_settings(ROOT_URLCONF='myapp.urls')`, I have to create single line urls.py for the tests, just to have the include which would not ignore the namespace. In my opinion, this commonly leads to just removing the namespace from the application URLs, which makes the problem apparently go away.

The #<a href="https://www.google.com/url?q=https%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;">28413 also resulted in somewhat questionable output with no change at all. Apparently that wasn't good call, since this problem keeps recurring.

I suggest to do one of these things:
 * Take the ROOT_URLCONF namespace into account if it have any.
 * Document that ROOT_URLCONF can't have namespace AND provide a warning through Django system check framework.

Personally, I'd go for the first option, which I think has negligible impact on the performance and may promote a correct usage of the URL namespaces in third party applications.

Regards
Vlastimil

Dne čtvrtek 15. února 2018 18:03:44 UTC+1 Tim Graham napsal(a):
The issue was raised some months ago in <a href="https://code.djangoproject.com/ticket/28413" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;">https://code.djangoproject.com/ticket/28413 and came to a similar conclusion. The resolution was to document the restriction.

On Thursday, February 15, 2018 at 10:57:54 AM UTC-5, Florian Apolloner wrote:
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

Dne čtvrtek 15. února 2018 18:03:44 UTC+1 Tim Graham napsal(a):
The issue was raised some months ago in <a href="https://code.djangoproject.com/ticket/28413" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;">https://code.djangoproject.com/ticket/28413 and came to a similar conclusion. The resolution was to document the restriction.

On Thursday, February 15, 2018 at 10:57:54 AM UTC-5, Florian Apolloner wrote:
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

Dne čtvrtek 15. února 2018 18:03:44 UTC+1 Tim Graham napsal(a):
The issue was raised some months ago in <a href="https://code.djangoproject.com/ticket/28413" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F28413\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHbscmoZWZ68K0qWMLt7VT-nJJVGw&#39;;return true;">https://code.djangoproject.com/ticket/28413 and came to a similar conclusion. The resolution was to document the restriction.

On Thursday, February 15, 2018 at 10:57:54 AM UTC-5, Florian Apolloner wrote:
Hi,

On Thursday, February 15, 2018 at 2:40:07 PM UTC+1, Vlastimil Zíma wrote:
Is there a reason not to use namespace from root urlconf? Can we change that, i.e. make root resolver to load the app_name of the root urls? Did I missed something else?

I don't think there is any reason to not allow it. That said the usefulness seems kinda questionable to me (ie if you enable the admin you already have another app for the root urlconf). In that sense I'd say: patches welcome and there is nothing obvious speaking against merging them as long as they don't introduce performance issues.

Cheers,
Florian

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/48ee0d68-3693-4e3d-81ef-83f0060dc741%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Allow namespaced reusable app urls as ROOT_URLCONF

Florian Apolloner
In reply to this post by Vlastimil Zíma-2


On Friday, February 16, 2018 at 3:08:33 PM UTC+1, Vlastimil Zíma wrote:
but to respect namespace if a ROOT_URLCONF has one.

I understood it like that; but as I said I didn't see many valid usecases. Your point about testing though is a good one!

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/33c414b4-e87f-4500-a19e-9c3aae5c2c2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.