Are URL namespaces optional or are they used by default by Django?

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

Are URL namespaces optional or are they used by default by Django?

Stodge
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Are URL namespaces optional or are they used by default by Django?

Andréas Kühne
Hi,

Namespaces are completely optional - you don't have to use it if you don't want to. 

What is happening that makes you think otherwise? What errors are you seeing?

Regards,

Andréas

2017-12-21 16:38 GMT+01:00 Stodge <[hidden email]>:
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCcqBOC2mLpfOm-hikHh3fE70iwLTZC6y%2BmOx%3DOd0E%2BvDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Are URL namespaces optional or are they used by default by Django?

Stodge
Thanks Andreas,

I'm seeing three things;

1) Reverse URLs are failing until I specifically add the app's name as a namespace
2) The show_urls management command from the django_extensions project appears to show that all URLs have a namespace:

/license/license/edit/<license_id>/ core.decorators.WVCheckLoginPermissions() license:edit_license

3) All resource URIs in TastyPie are empty, which according to a ticket I found there seems to be caused by namespaces.

Thanks
Mike


On Thursday, 21 December 2017 10:47:28 UTC-5, Andréas Kühne wrote:
Hi,

Namespaces are completely optional - you don't have to use it if you don't want to. 

What is happening that makes you think otherwise? What errors are you seeing?

Regards,

Andréas

2017-12-21 16:38 GMT+01:00 Stodge <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="axPtVl_HDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sto...@...>:
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="axPtVl_HDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="axPtVl_HDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/2f722055-c058-4d06-b4e7-ca47b2511769%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1816bc1d-c5ef-4814-9e11-2ce45c8db802%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Are URL namespaces optional or are they used by default by Django?

Stodge
In reply to this post by Stodge
I am using a prefix when I include the URLs for each app:

for app in settings.SITE_APPS.get_application_list():    
    url_prefix
= r'^%s/' % app
        urlpatterns
+= [
            url
(prefix, include(url_include)),

       
]

I just assumed this isn't using namespaces because I'm not using the namespace parameter on include()?



On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Are URL namespaces optional or are they used by default by Django?

Andréas Kühne
Ok,

You have not namespaced anything, but you have added the api name infront of the URLs you are adding.

So for example, I am guessing that you in your urls.py file for the license app have added "/license/edit/<license_id>/" for the license detail page? Because you have already added the license part with the prefix you have added here:

for app in settings.SITE_APPS.get_application_list():    
    url_prefix 
= r'^%s/' % app
        urlpatterns 
+= [
            url
(prefix, include(url_include)),

        
]


So you have added license twice, and therefore you will need to add it twice when you call the urls as well.

You should probably do this instead:
for app in settings.SITE_APPS.get_application_list():    
    url_prefix 
= r'^%s/' % app
        urlpatterns 
+= [
            url
('', include(url_include)),

        
]



If you don't want that extra license part.

Namespace is added the way you suggested via:
url('', include(url_include, namespace="license"))

Also, it doesn't result in an extra app part (in this case license), it only adds the namespace in the call to reserve, so if you had setup the namespace like i wrote here, you would use: 
reverse("license:license_detail", args=(1, ))

Hope I have explained it good enough :-)

Regards,

Andréas

2017-12-21 17:02 GMT+01:00 Stodge <[hidden email]>:
I am using a prefix when I include the URLs for each app:

for app in settings.SITE_APPS.get_application_list():    
    url_prefix
= r'^%s/' % app
        urlpatterns
+= [
            url
(prefix, include(url_include)),

       
]

I just assumed this isn't using namespaces because I'm not using the namespace parameter on include()?



On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCfOYNfWT0hd-szZ52FQTbFP-VZL2UxcfCX0-E2HJAP2ew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Are URL namespaces optional or are they used by default by Django?

Stodge
Thanks,

My edit license URL is:

    url(r'^license/edit/(?P<license_id>\d+)/$', views.edit_license, name='edit_license'),

However, this is what I want and it has been this way for years. My URLs are organised:

/<app_name>/<resource_name>/

I don't think this explains why my URLs are all namespaced when I haven't changed my code and my code doesn't use namespaces. I'm really confused. :)

Thanks again
Mike





On Thursday, 21 December 2017 11:38:42 UTC-5, Andréas Kühne wrote:
Ok,

You have not namespaced anything, but you have added the api name infront of the URLs you are adding.

So for example, I am guessing that you in your urls.py file for the license app have added "/license/edit/<license_id>/" for the license detail page? Because you have already added the license part with the prefix you have added here:

for app in settings.SITE_APPS.get_application_list():    
    url_prefix 
= r'^%s/' % app
        urlpatterns 
+= [
            url
(prefix, include(url_include)),

        
]


So you have added license twice, and therefore you will need to add it twice when you call the urls as well.

You should probably do this instead:
for app in settings.SITE_APPS.get_application_list():    
    url_prefix 
= r'^%s/' % app
        urlpatterns 
+= [
            url
('', include(url_include)),

        
]



If you don't want that extra license part.

Namespace is added the way you suggested via:
url('', include(url_include, namespace="license"))

Also, it doesn't result in an extra app part (in this case license), it only adds the namespace in the call to reserve, so if you had setup the namespace like i wrote here, you would use: 
reverse("license:license_detail", args=(1, ))

Hope I have explained it good enough :-)

Regards,

Andréas

2017-12-21 17:02 GMT+01:00 Stodge <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="qG_LKCvKDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sto...@...>:
I am using a prefix when I include the URLs for each app:

for app in settings.SITE_APPS.get_application_list():    
    url_prefix
= r'^%s/' % app
        urlpatterns
+= [
            url
(prefix, include(url_include)),

       
]

I just assumed this isn't using namespaces because I'm not using the namespace parameter on include()?



On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="qG_LKCvKDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="qG_LKCvKDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com.

For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6e29c8fd-f13d-4281-a047-622dc8868147%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Are URL namespaces optional or are they used by default by Django?

Andréas Kühne
Hi again,

I don't understand what you mean then. Because you say that they are namespaced. What I mean by that is that when using reverse, you have to use: 
reverse("license:edit_license", args=(1, )). 

However, if this is the code you have used:
for app in settings.SITE_APPS.get_application_list():    
    url_prefix 
= r'^%s/' % app
        urlpatterns 
+= [
            url
(prefix, include(url_include)),

        
]

Then that won't work either - because you add the prefix variable to the urlpattern and not the url_prefix variable. So this would add it the same way I wanted to add it:

url('', include(url_include))

So I would fix that first at least.

Regards,

Andréas

2017-12-21 17:58 GMT+01:00 Stodge <[hidden email]>:
Thanks,

My edit license URL is:

    url(r'^license/edit/(?P<license_id>\d+)/$', views.edit_license, name='edit_license'),

However, this is what I want and it has been this way for years. My URLs are organised:

/<app_name>/<resource_name>/

I don't think this explains why my URLs are all namespaced when I haven't changed my code and my code doesn't use namespaces. I'm really confused. :)

Thanks again
Mike





On Thursday, 21 December 2017 11:38:42 UTC-5, Andréas Kühne wrote:
Ok,

You have not namespaced anything, but you have added the api name infront of the URLs you are adding.

So for example, I am guessing that you in your urls.py file for the license app have added "/license/edit/<license_id>/" for the license detail page? Because you have already added the license part with the prefix you have added here:

for app in settings.SITE_APPS.get_application_list():    
    url_prefix 
= r'^%s/' % app
        urlpatterns 
+= [
            url
(prefix, include(url_include)),

        
]


So you have added license twice, and therefore you will need to add it twice when you call the urls as well.

You should probably do this instead:
for app in settings.SITE_APPS.get_application_list():    
    url_prefix 
= r'^%s/' % app
        urlpatterns 
+= [
            url
('', include(url_include)),

        
]



If you don't want that extra license part.

Namespace is added the way you suggested via:
url('', include(url_include, namespace="license"))

Also, it doesn't result in an extra app part (in this case license), it only adds the namespace in the call to reserve, so if you had setup the namespace like i wrote here, you would use: 
reverse("license:license_detail", args=(1, ))

Hope I have explained it good enough :-)

Regards,

Andréas

2017-12-21 17:02 GMT+01:00 Stodge <[hidden email]>:
I am using a prefix when I include the URLs for each app:

for app in settings.SITE_APPS.get_application_list():    
    url_prefix
= r'^%s/' % app
        urlpatterns
+= [
            url
(prefix, include(url_include)),

       
]

I just assumed this isn't using namespaces because I'm not using the namespace parameter on include()?



On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b471c11c-2d33-4f47-83a2-36209edd4ea0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6e29c8fd-f13d-4281-a047-622dc8868147%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCcRCTMR9QZLCmpxX0%3DhsCU_ax7JUcA%3DZcjTieetM3nJcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Are URL namespaces optional or are they used by default by Django?

Stodge
In reply to this post by Stodge
Problem solved and apparently it was my silly mistake! While experimenting I added app_name to my urls files. Apparently this enables namespace support. So I removed them from my urls files and it works.

Thanks

On Thursday, 21 December 2017 10:38:36 UTC-5, Stodge wrote:
I am porting an app from Django 1.6.x to 1.10.x and I'm hitting a problem with URL namespaces. I don't specifically configure any namespaces in my URLs but Django seems to think that all my app URLs are namespaced. The documentation seems to imply that namespaces are optional and only configured if provided, but my experience suggests otherwise. Would someone be able to confirm if namespaces are optional (opt-in)? I'm really rather confused at the moment about this. Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" 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-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9126cdfd-81e5-48ee-97b9-ad62edaeff4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.