猿问

/v2/search/SARS_CoV_2/GID1716 处的 NoReverseMatch

我正在开发一个 django 应用程序,在该应用程序中,我试图通过 javascript 单击按钮将变量的值发送到后端。


javascript代码:


$(document).on("click", "#filter", function (e) {

      IUPredscorethreshold = 0.4

      $("#ksNetwork").empty();

      ksInteractionNetwork('{% url "camkinetv2:newinteractors_intnet" tab1.caMKipedia_Id IUPredscorethreshold %}');

 });

网址.py


path(

        "dataJson/newinteractors_intnet/<str:geneId>/<str:IUPredscorethreshold>",

        views.newinteractors_intnet,

        name="newinteractors_intnet",

    ),

视图.py


@csrf_exempt

def newinteractors_intnet(request, geneId, IUPredscorethreshold):


    print("IUPredscorethreshold:" + IUPredscorethreshold)


.

.

.

.

.

some computation



    graphData = {"nodes": uniquenodesdata, "links": linksdata}


    response = JsonResponse(graphData)


    return response


当我执行此代码时,我收到以下错误:


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>[^/]+)$']


我究竟做错了什么?我该如何解决这个问题。我仍处于 django 的学习阶段,我无法弄清楚如何解决这个错误。


尚方宝剑之说
浏览 84回答 3
3回答

哔哔one

错误消息说它找不到匹配的 url&nbsp;{% url "camkinetv2:newinteractors_intnet" tab1.caMKipedia_Id IUPredscorethreshold %}。你的 urls.py通过放在它前面来声明IUPredscorethreshold它是一个字符串。str:在您的 javascript 中,您分配0.4给该变量,它是一个整数。因此,您无法解析的网址。将 urls.py 中的路径更改为:&nbsp;path( "dataJson/newinteractors_intnet/<str:geneId>/<int:IUPredscorethreshold>", views.newinteractors_intnet, name="newinteractors_intnet", ),

守候你守候我

将您的 Javascript 代码更改为:$(document).on("click", "#filter", function (e) {&nbsp; IUPredscorethreshold = 0.4&nbsp; $("#ksNetwork").empty();&nbsp; let url = '{% url "camkinetv2:newinteractors_intnet" ' + tab1.caMKipedia_Id + ' ' + IUPredscorethreshold + '%}'&nbsp; ksInteractionNetwork(url);});我相信 url 没有正确形成

慕森卡

将javascript行从:更改ksInteractionNetwork('{% url "camkinetv2:newinteractors_intnet" tab1.caMKipedia_Id IUPredscorethreshold %}');&nbsp;为ksInteractionNetwork('{% url "camkinetv2:newinteractors_intnet" tab1.caMKipedia_Id "IUPredscorethreshold" %}'.replace(/IUPredscorethreshold/, IUPredscorethresholdvalues) );以下回答帮助回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答