django warning urls.W005 URL namespace isn't unique












0















I am having trouble understanding the following warning. I have a namespace called "v1" and I am using these namespaces to determine versioning in my API (using django rest framework). So, I have paths like these:



/v1/accounts/me
/v1/listings


Here is the URLs configuration (project/urls.py):



urlpatterns = [
path('admin/', admin.site.urls),
path('v1/accounts/', include('accounts.urls', namespace='v1')),
path('v1/listings/', include('listings.urls', namespace='v1'))
]


accounts/urls.py



app_name = 'accounts'

urlpatterns = [
url(r'^token/$', views.obtain_auth_token, name='obtain_token'),
url(r'^me/$', my_account, name='my_account'),
]


listings/urls.py



app_name = 'listings'

urlpatterns = [
path('', recent_listings, name='recent_listings')
]


Everything works as expected. All urls are dispatched. Versioning works. However, I keep getting the following error:




?: (urls.W005) URL namespace 'v1' isn't unique. You may not be able to reverse all URLs in this namespace




I know it is a warning and I might be able to suppress it; however, I want to understand why this is happening. Based on my URLconf and this warning, it seems like there cannot be multiple namespaced paths as "siblings." They need to be children of one namespaced path (e.g "v1"). If my understanding is correct, how am I supposed to create this URL configuration.










share|improve this question



























    0















    I am having trouble understanding the following warning. I have a namespace called "v1" and I am using these namespaces to determine versioning in my API (using django rest framework). So, I have paths like these:



    /v1/accounts/me
    /v1/listings


    Here is the URLs configuration (project/urls.py):



    urlpatterns = [
    path('admin/', admin.site.urls),
    path('v1/accounts/', include('accounts.urls', namespace='v1')),
    path('v1/listings/', include('listings.urls', namespace='v1'))
    ]


    accounts/urls.py



    app_name = 'accounts'

    urlpatterns = [
    url(r'^token/$', views.obtain_auth_token, name='obtain_token'),
    url(r'^me/$', my_account, name='my_account'),
    ]


    listings/urls.py



    app_name = 'listings'

    urlpatterns = [
    path('', recent_listings, name='recent_listings')
    ]


    Everything works as expected. All urls are dispatched. Versioning works. However, I keep getting the following error:




    ?: (urls.W005) URL namespace 'v1' isn't unique. You may not be able to reverse all URLs in this namespace




    I know it is a warning and I might be able to suppress it; however, I want to understand why this is happening. Based on my URLconf and this warning, it seems like there cannot be multiple namespaced paths as "siblings." They need to be children of one namespaced path (e.g "v1"). If my understanding is correct, how am I supposed to create this URL configuration.










    share|improve this question

























      0












      0








      0








      I am having trouble understanding the following warning. I have a namespace called "v1" and I am using these namespaces to determine versioning in my API (using django rest framework). So, I have paths like these:



      /v1/accounts/me
      /v1/listings


      Here is the URLs configuration (project/urls.py):



      urlpatterns = [
      path('admin/', admin.site.urls),
      path('v1/accounts/', include('accounts.urls', namespace='v1')),
      path('v1/listings/', include('listings.urls', namespace='v1'))
      ]


      accounts/urls.py



      app_name = 'accounts'

      urlpatterns = [
      url(r'^token/$', views.obtain_auth_token, name='obtain_token'),
      url(r'^me/$', my_account, name='my_account'),
      ]


      listings/urls.py



      app_name = 'listings'

      urlpatterns = [
      path('', recent_listings, name='recent_listings')
      ]


      Everything works as expected. All urls are dispatched. Versioning works. However, I keep getting the following error:




      ?: (urls.W005) URL namespace 'v1' isn't unique. You may not be able to reverse all URLs in this namespace




      I know it is a warning and I might be able to suppress it; however, I want to understand why this is happening. Based on my URLconf and this warning, it seems like there cannot be multiple namespaced paths as "siblings." They need to be children of one namespaced path (e.g "v1"). If my understanding is correct, how am I supposed to create this URL configuration.










      share|improve this question














      I am having trouble understanding the following warning. I have a namespace called "v1" and I am using these namespaces to determine versioning in my API (using django rest framework). So, I have paths like these:



      /v1/accounts/me
      /v1/listings


      Here is the URLs configuration (project/urls.py):



      urlpatterns = [
      path('admin/', admin.site.urls),
      path('v1/accounts/', include('accounts.urls', namespace='v1')),
      path('v1/listings/', include('listings.urls', namespace='v1'))
      ]


      accounts/urls.py



      app_name = 'accounts'

      urlpatterns = [
      url(r'^token/$', views.obtain_auth_token, name='obtain_token'),
      url(r'^me/$', my_account, name='my_account'),
      ]


      listings/urls.py



      app_name = 'listings'

      urlpatterns = [
      path('', recent_listings, name='recent_listings')
      ]


      Everything works as expected. All urls are dispatched. Versioning works. However, I keep getting the following error:




      ?: (urls.W005) URL namespace 'v1' isn't unique. You may not be able to reverse all URLs in this namespace




      I know it is a warning and I might be able to suppress it; however, I want to understand why this is happening. Based on my URLconf and this warning, it seems like there cannot be multiple namespaced paths as "siblings." They need to be children of one namespaced path (e.g "v1"). If my understanding is correct, how am I supposed to create this URL configuration.







      python django django-urls






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 23:23









      GasimGasim

      3,05363470




      3,05363470
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Basically what happens is that, namespace plays a significant role on reverse finding the url. For example:



          In your example reverse('v1:obtain_token') will return /v1/accounts/token/. Lets say you have two urls with same name in accounts and listings, then you might not be able to find accounts url in reverse query. That is why the warning is for. Better if you use different namespaces for each include. In you case, it should be:



          path('v1/accounts/', include('accounts.urls', namespace='accounts')),
          path('v1/listings/', include('listings.urls', namespace='listings'))


          Please read the documentations for more details.



          Update



          you can do the versioning like this:



          path('accounts/', include('accounts.urls', namespace='accounts')),  # accounts url 


          inside accounts app:



          path('v1/token/', views.obtain_auth_token, name='obtain_token_v1'),
          path('v2/token/', views.obtain_auth_token2, name='obtain_token_v2'),
          ...





          share|improve this answer


























          • Understood thanks. It doesn't make sense for me to have different namespaces because I am relying on them for versioning. Nested namespaces might work but from everything that I have looked at, I need to create a separate app for that namespace (include function throws error app name must be specified). Do you know if there is a way to disable this warning?

            – Gasim
            Nov 26 '18 at 0:25











          • you are doing the versioning without the namespaces. You have defined v1/.../ which already signifies the versioning. But maybe its more suited to do the versioning like this /accounts/v1/token. Please see my updated answer.

            – ruddra
            Nov 26 '18 at 0:49








          • 1





            Thank you for the help! I am going to play with it a bit more. Writing versions per app url is an interesting idea.

            – Gasim
            Nov 27 '18 at 11:17











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473027%2fdjango-warning-urls-w005-url-namespace-isnt-unique%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Basically what happens is that, namespace plays a significant role on reverse finding the url. For example:



          In your example reverse('v1:obtain_token') will return /v1/accounts/token/. Lets say you have two urls with same name in accounts and listings, then you might not be able to find accounts url in reverse query. That is why the warning is for. Better if you use different namespaces for each include. In you case, it should be:



          path('v1/accounts/', include('accounts.urls', namespace='accounts')),
          path('v1/listings/', include('listings.urls', namespace='listings'))


          Please read the documentations for more details.



          Update



          you can do the versioning like this:



          path('accounts/', include('accounts.urls', namespace='accounts')),  # accounts url 


          inside accounts app:



          path('v1/token/', views.obtain_auth_token, name='obtain_token_v1'),
          path('v2/token/', views.obtain_auth_token2, name='obtain_token_v2'),
          ...





          share|improve this answer


























          • Understood thanks. It doesn't make sense for me to have different namespaces because I am relying on them for versioning. Nested namespaces might work but from everything that I have looked at, I need to create a separate app for that namespace (include function throws error app name must be specified). Do you know if there is a way to disable this warning?

            – Gasim
            Nov 26 '18 at 0:25











          • you are doing the versioning without the namespaces. You have defined v1/.../ which already signifies the versioning. But maybe its more suited to do the versioning like this /accounts/v1/token. Please see my updated answer.

            – ruddra
            Nov 26 '18 at 0:49








          • 1





            Thank you for the help! I am going to play with it a bit more. Writing versions per app url is an interesting idea.

            – Gasim
            Nov 27 '18 at 11:17
















          1














          Basically what happens is that, namespace plays a significant role on reverse finding the url. For example:



          In your example reverse('v1:obtain_token') will return /v1/accounts/token/. Lets say you have two urls with same name in accounts and listings, then you might not be able to find accounts url in reverse query. That is why the warning is for. Better if you use different namespaces for each include. In you case, it should be:



          path('v1/accounts/', include('accounts.urls', namespace='accounts')),
          path('v1/listings/', include('listings.urls', namespace='listings'))


          Please read the documentations for more details.



          Update



          you can do the versioning like this:



          path('accounts/', include('accounts.urls', namespace='accounts')),  # accounts url 


          inside accounts app:



          path('v1/token/', views.obtain_auth_token, name='obtain_token_v1'),
          path('v2/token/', views.obtain_auth_token2, name='obtain_token_v2'),
          ...





          share|improve this answer


























          • Understood thanks. It doesn't make sense for me to have different namespaces because I am relying on them for versioning. Nested namespaces might work but from everything that I have looked at, I need to create a separate app for that namespace (include function throws error app name must be specified). Do you know if there is a way to disable this warning?

            – Gasim
            Nov 26 '18 at 0:25











          • you are doing the versioning without the namespaces. You have defined v1/.../ which already signifies the versioning. But maybe its more suited to do the versioning like this /accounts/v1/token. Please see my updated answer.

            – ruddra
            Nov 26 '18 at 0:49








          • 1





            Thank you for the help! I am going to play with it a bit more. Writing versions per app url is an interesting idea.

            – Gasim
            Nov 27 '18 at 11:17














          1












          1








          1







          Basically what happens is that, namespace plays a significant role on reverse finding the url. For example:



          In your example reverse('v1:obtain_token') will return /v1/accounts/token/. Lets say you have two urls with same name in accounts and listings, then you might not be able to find accounts url in reverse query. That is why the warning is for. Better if you use different namespaces for each include. In you case, it should be:



          path('v1/accounts/', include('accounts.urls', namespace='accounts')),
          path('v1/listings/', include('listings.urls', namespace='listings'))


          Please read the documentations for more details.



          Update



          you can do the versioning like this:



          path('accounts/', include('accounts.urls', namespace='accounts')),  # accounts url 


          inside accounts app:



          path('v1/token/', views.obtain_auth_token, name='obtain_token_v1'),
          path('v2/token/', views.obtain_auth_token2, name='obtain_token_v2'),
          ...





          share|improve this answer















          Basically what happens is that, namespace plays a significant role on reverse finding the url. For example:



          In your example reverse('v1:obtain_token') will return /v1/accounts/token/. Lets say you have two urls with same name in accounts and listings, then you might not be able to find accounts url in reverse query. That is why the warning is for. Better if you use different namespaces for each include. In you case, it should be:



          path('v1/accounts/', include('accounts.urls', namespace='accounts')),
          path('v1/listings/', include('listings.urls', namespace='listings'))


          Please read the documentations for more details.



          Update



          you can do the versioning like this:



          path('accounts/', include('accounts.urls', namespace='accounts')),  # accounts url 


          inside accounts app:



          path('v1/token/', views.obtain_auth_token, name='obtain_token_v1'),
          path('v2/token/', views.obtain_auth_token2, name='obtain_token_v2'),
          ...






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 0:50

























          answered Nov 25 '18 at 23:33









          ruddraruddra

          13.8k32748




          13.8k32748













          • Understood thanks. It doesn't make sense for me to have different namespaces because I am relying on them for versioning. Nested namespaces might work but from everything that I have looked at, I need to create a separate app for that namespace (include function throws error app name must be specified). Do you know if there is a way to disable this warning?

            – Gasim
            Nov 26 '18 at 0:25











          • you are doing the versioning without the namespaces. You have defined v1/.../ which already signifies the versioning. But maybe its more suited to do the versioning like this /accounts/v1/token. Please see my updated answer.

            – ruddra
            Nov 26 '18 at 0:49








          • 1





            Thank you for the help! I am going to play with it a bit more. Writing versions per app url is an interesting idea.

            – Gasim
            Nov 27 '18 at 11:17



















          • Understood thanks. It doesn't make sense for me to have different namespaces because I am relying on them for versioning. Nested namespaces might work but from everything that I have looked at, I need to create a separate app for that namespace (include function throws error app name must be specified). Do you know if there is a way to disable this warning?

            – Gasim
            Nov 26 '18 at 0:25











          • you are doing the versioning without the namespaces. You have defined v1/.../ which already signifies the versioning. But maybe its more suited to do the versioning like this /accounts/v1/token. Please see my updated answer.

            – ruddra
            Nov 26 '18 at 0:49








          • 1





            Thank you for the help! I am going to play with it a bit more. Writing versions per app url is an interesting idea.

            – Gasim
            Nov 27 '18 at 11:17

















          Understood thanks. It doesn't make sense for me to have different namespaces because I am relying on them for versioning. Nested namespaces might work but from everything that I have looked at, I need to create a separate app for that namespace (include function throws error app name must be specified). Do you know if there is a way to disable this warning?

          – Gasim
          Nov 26 '18 at 0:25





          Understood thanks. It doesn't make sense for me to have different namespaces because I am relying on them for versioning. Nested namespaces might work but from everything that I have looked at, I need to create a separate app for that namespace (include function throws error app name must be specified). Do you know if there is a way to disable this warning?

          – Gasim
          Nov 26 '18 at 0:25













          you are doing the versioning without the namespaces. You have defined v1/.../ which already signifies the versioning. But maybe its more suited to do the versioning like this /accounts/v1/token. Please see my updated answer.

          – ruddra
          Nov 26 '18 at 0:49







          you are doing the versioning without the namespaces. You have defined v1/.../ which already signifies the versioning. But maybe its more suited to do the versioning like this /accounts/v1/token. Please see my updated answer.

          – ruddra
          Nov 26 '18 at 0:49






          1




          1





          Thank you for the help! I am going to play with it a bit more. Writing versions per app url is an interesting idea.

          – Gasim
          Nov 27 '18 at 11:17





          Thank you for the help! I am going to play with it a bit more. Writing versions per app url is an interesting idea.

          – Gasim
          Nov 27 '18 at 11:17


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473027%2fdjango-warning-urls-w005-url-namespace-isnt-unique%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Futebolista

          Jornalista