Django.urls.exceptions.NoReverseMatch error while trying to use reverse [duplicate]

I have a problem with reverse function in Django. In my project I have an app called posts and I am trying to test it.

class PostListViewTest(TestCase):
    def test_future_post_list(self):
        post = create_post('Future', 2)
        response = self.client.get(reverse('posts:all'))

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "No posts available")
        self.assertQuerySetEqual(response.context['posts_list'], [])

In main urls.py I have

from django.conf import settings
from django.contrib import admin
from django.urls import include, path

from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('posts/', include("posts.urls")),
    path('aboutme/', include("aboutme.urls"))
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

in posts/urls.py I have

# urls.py
from django.urls import path
from . import views  # Ensure this import is correct

urlpatterns = [
    path("allposts/", views.AllPostsView.as_view(), name="all"),
    path("<int:pk>/", views.PostDetailView.as_view(), name="detail")
]

my INSTALED_APPS

    INSTALLED_APPS = [
    'posts.apps.PostsConfig',
    'notifications.apps.NotificationsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sorl.thumbnail',
    'huey.contrib.djhuey'

]

but when I am trying to run tests I get django.urls.exceptions.NoReverseMatch: 'posts' is not a registered namespace when I use reverse('all') instead of reverse('posts:all') everything works perfectly

Tried to catch typos but didn't fount them

Back to Top