简体   繁体   中英

passing a parameter in the reverse url in javascript

javascript

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

id is the variable (1000)

urls.py

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

it throws this error: Caught NoReverseMatch while rendering: Reverse for 'cand_resume' with arguments '(u'cnds_id',)' and keyword arguments '{}' not found.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM