Dynamic URL routing is not working in django web application

A am working on a simple application, where trying to generate Dynamic URl and routing take place as per the ID in the url. Dynamic value is getting populated in the URL, but it not performing action that needed.

prop_listings.html HTML Page:-

 <div class="row text-secondary pb-2">
   <div class="col-6">
    <i class="fas fa-clock"></i> {{ listing.list_date | timesince }}
   </div>
  </div>
  <hr>
  <a href="{% url 'morelisting' listing.id %}" class="btn btn-primary btn-block">More Info</a>
       </div>
      </div>
      </div>

URL.py in App Listings:-

from django.urls import path
from . import views

urlpatterns = [
    path('',views.PropListings,name="prop_listings"),
    path('<int:listing_id>', views.mlisting, name="morelisting"),

]

Views.py :-

def mlisting(request, listing_id):
#  listingDetl = get_object_or_404(Listing, pk=listing_id)
  listingDetl = Listing.objects.get(pk=listing_id)
  print(listingDetl.username, listingDetl.address,listingDetl.city)

  context = {
    'listingDetails': listingDetl
  }

  return render(request,'listings/detail_listing.html', context)

URL.py in MainProject:-

urlpatterns = [
    path('', include('static_pages.urls')),
    path('user_account/', include('user_account.urls')),
    path('listings/', include('listings.urls')),
    path('feedback/', include('feedback.urls')),
    path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Am trying to redirect the page from prop_listings.html to detail_listing.html, based on the below tag URL generated on listing.id

<a href="{% url 'morelisting' listing.id %}" class="btn btn-primary btn-block">More Info</a> 

It's not working as expected on-click of above tag. But when i did inspect on the same, URL is getting generated properly and when i click on the url, it will work as expected.

Inspect on the html page, URL populated

I looked into similar issue threads and tried to make changes, but not able to fix it. Not getting what the issue and how to correct it.

Back to Top