I am developing a django application in which I am trying to send a value of the variable to the backend on click of a button through javascript.
javascript code:
$(document).on("click", "#filter", function (e) { IUPredscorethreshold = 0.4 $("#ksNetwork").empty(); ksInteractionNetwork('{% url "camkinetv2:newinteractors_intnet" tab1.caMKipedia_Id IUPredscorethreshold %}'); });
urls.py
path( "dataJson/newinteractors_intnet/<str:geneId>/<str:IUPredscorethreshold>", views.newinteractors_intnet, name="newinteractors_intnet", ),
views.py
@csrf_exempt def newinteractors_intnet(request, geneId, IUPredscorethreshold): print("IUPredscorethreshold:" + IUPredscorethreshold) . . . . . some computation graphData = {"nodes": uniquenodesdata, "links": linksdata} response = JsonResponse(graphData) return response
when I execute this code i am getting following error:
NoReverseMatch at /v2/search/SARS_CoV_2/GID1716 Reverse for 'newinteractors_intnet' with arguments '('GID1716', '')' not found. 1 pattern(s) tried: ['v2/dataJson/newinteractors_intnet/(?P<geneId>[^/]+)/(?P<IUPredscorethreshold>[^/]+)$'] Exception Value: Reverse for 'newinteractors_intnet' with arguments '('GID1716', '')' not found. 1 pattern(s) tried: ['v2/dataJson/newinteractors_intnet/(?P<geneId>[^/]+)/(?P<IUPredscorethreshold>[^/]+)$']
what am I doing wrong? how can I solve this issue. I am still at learning stage of django and I am not able to figure out how to solve this error.
Advertisement
Answer
The error message says it couldn’t find a url that matches {% url "camkinetv2:newinteractors_intnet" tab1.caMKipedia_Id IUPredscorethreshold %}
. Your urls.py declares IUPredscorethreshold
to be a string by putting str:
in front of it. In your javascript you assign 0.4
to that variable which is an integer. Therefore, the url you doesn’t resolve.
Change your path in urls.py to:
path( "dataJson/newinteractors_intnet/<str:geneId>/<int:IUPredscorethreshold>", views.newinteractors_intnet, name="newinteractors_intnet", ),