'Why one url the doesn't require an auth asks for token when placed below a url that requires auth

I obeserved a weird error(maybe) while testing my apis. I have three views handleing the api requests. Two doen't require auth (searchListing, listListing) and on requires auth (retrieveListing). Weirdly if I keep the 'search' below the 'str:slug'' url (urlpatern_1) it says Authentication credentials were not provided. However if I move the search above the 'str:slug'' it works perfectly.

urlpatterns_1 = [
    
    path('', views.listListing , name= 'listListing'),
    path('<str:slug>', views.retrieveListing , name= 'retrieveList'),
    path('search', views.searchListing , name= 'searchList'),

]
urlpatterns_2 = [
    
    path('', views.listListing , name= 'listListing'),
    path('search', views.searchListing , name= 'searchList'),
    path('<str:slug>', views.retrieveListing , name= 'retrieveList'),

]

But weirdly again the 'listListing' is unaffected by its position.

Please explain me why is this happening

views.py

@api_view(['GET'])
def listListing(request):
    pass

@api_view(['GET'])
@permission_classes([IsAuthenticated])
def retrieveListing(request, slug):
     pass

@api_view(['GET'])
def searchListing(request):
    pass


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source