Hi

When I open the Django shell (python manage.py shell) and test a reverse
URL:

>>> from django.urls import reverse
>>> reverse('admin:locales_site_changelist')
'/admin/locales/site/'

then it works as expected.

However, when I try and use the same lookup string via a unit test:

from django.test import TestCase
from core.models import CustomUser as User

class TestCaseSimple(TestCase):

    def setUp(self):
        User.objects.create_superuser(
            email='t...@example.com',
            password='password')
        self.login = self.client.login(
            email='t...@example.com',
            password='password')
        print('Login successful? ', self.login)  # True
        url = reverse('admin:locales_site_changelist')


I get this error:

E       django.urls.exceptions.NoReverseMatch: Reverse for
'locales_site_changelist' not found. 'locales_site_changelist' is not a
valid view function or pattern name.


Is there some simple reason why reverse lookup does not work when testing?
(I actually need to use it in a client post request.)

Thanks
Derek

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF1Wu3NmqC%2BqWK9v%3DNXa%3DOaLc2N3p1dkZ40r1n7gXuCk1gDaQQ%40mail.gmail.com.

Reply via email to