1

javascript

   var url = '{% url cand_resume "cnd_id" %}';   
   url = url.replace("cnd_id",id);
   cell2.innerHTML= '<a href="' + url + '"> View</a>';

id 是变量 (1000)

网址.py

       url(r'^(?P<cnd_id>\d*)/resume/', 'download_resume',name='cand_resume'),

它抛出此错误:渲染时捕获 NoReverseMatch:使用参数“(u'cnds_id',)”和关键字参数“{}”反转“cand_resume”。

4

1 回答 1

1

I guess when you parse your url

var url = '{% url cand_resume "cnd_id" %}';  

you sending a string cnd_id which will not match your url.

try (not sure if you need quite around your function name)

var url = '{% url cand_resume 1000 %}'; 

or something like (id is variable from django)

var url = '{% url cand_resume id %}'; 

You can try dirty trick like

var url = '{% url cand_resume 1000 %}'.replace (1000, cnd_id);

or check out this lib https://github.com/mlouro/django-js-utils

于 2013-09-05T12:14:44.267 回答