I am building a page which holds some categories and when user clicks on a link, then I go ahead and fetch the details for that specific category (products of that category). The way to do this, I thought, was to use jQuery Ajax. Anyway, the part where i append my data is like this:
...
$.ajax({
...
success: function(results) {
$("#cards").empty();
for (let iterator = results.length -1; iterator>=0; iterator--) {
$("#cards").append(
'<a href="{% url "product" '+results[iterator].id+' %}">'
+'<div>'
+ '<div class="card mb-5 shadow-sm">'
+ '<img class="card-img-top"'
+ 'src="'+results[iterator].image+'" />'
+ '<div class="card-body">'
+ '<h5 class="card-title">'+results[iterator].name+'</h5>'
+ '<p class="card-text">'+results[iterator].price+'</p>'
+ '</div>'
+ '</div>'
+'</div>'
+'</a>'
);
}
},
...
});
...
Based on this block of code, i get this error:
Reverse for 'product' with arguments '('+results[iterator].id+',)' not found. 1 pattern(s) tried: ['(?P<id>[0-9]+)/$']
Since i get the results in form of json i don't have a problem with using it the way i did, but the problem rises when adding the a tag around my container div. I don't understand what course of action I should take since i'm not really experience with neither Django nor jQuery.