Below is my code. 'n' logs correctly in the console, and everything works perfectly if I manually enter the value for 'n' into url: '{% url "delete_photo" iddy=2%}'
. Alas, when I try to use 'n' as a variable (seen below) it gives me a reverse match not found error. Can anyone help with this?
javascript
function test(n){console.log(n);$.ajax({type: 'get',url: '{% url "delete_photo" iddy=n%}',datatype:'json',success: function(data){alert(n)console.log(data)console.log(n)},error: console.log("SSS"),});}
html
{% for t in photos %}
<div id="photobox" ><img id="img_pb3"src="{{t.photo.url}}">
<div><a><span onclick="test({{t.id}})" class="closeBtn">×</span></div></a>
</div>
{% endfor %}
urls
urlpatterns = [path('', views.explore, name='explore'),path('home/', views.home, name='home'),path('home/comment', views.comment, name='comment'),path('home/photo_del/<iddy>', views.delete_photo, name='delete_photo')
]
views
def delete_photo(request, iddy):data = {'a':iddy, 'b': iddy}return JsonResponse(data, safe=False)