Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

django.urls.exceptions.NoReverseMatch: 'users' is not a registered namespace inside 'v1'

#main url

from django.contrib import admin

from django.urls import path,include

urlpatterns = [
path('admin/', admin.site.urls),
path('api/v1/', include('users.api.urls',namespace='v1')),

]

#app url

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

from django.urls import path
from .views import ExampleView

app_name='users'

urlpatterns=[
path("", ExampleView.as_view(), name='home')
]

app view

from rest_framework.views import Response, APIView


class ExampleView(APIView):

def get(self, request):
    return Response({"message": "hello world"})

test app

from django.urls import reverse
from rest_framework.test import APISimpleTestCase


class TestUser(APISimpleTestCase):

def setUp(self):

    self.path1 = reverse('v1:users:home')

def test_user_path(self):
    print(self.path1)

what is wrong with this code? why it return django.urls.exceptions.NoReverseMatch: ‘users’ is not a registered namespace inside ‘v1’

>Solution :

Try the following:

reverse('v1:home')

You have already changed the namespace of users to v1. Since users is not a URL path name in the app’s urls.py, you get an error.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading