I am trying to pass a variable through the Django template url tag with little success.
My path in the urls.py:
path("viewListing/<int:listingID>", views.bookListing, name="viewListing")
In the template, I am using javascript to generate the listingID with a for loop.
for(j=0; j<5; j++){
var thisID = (data[j].id)
imgA.href = "{% url 'viewListing' thisID %}";
}
However, I am getting this error
Reverse for 'viewListing' with arguments '('',)' not found. 1 pattern(s) tried: ['viewListing/(?P<listingID>[0-9]+)$']
If I pass a number instead of thisID, for instance 1, the code works fine.
So my question is, how can I make this work with a variable.