在javascript中传递反向url中的参数 [英] passing a parameter in the reverse url in javascript

查看:76
本文介绍了在javascript中传递反向url中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript

javascript

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

id是变量(1000)

id is the variable (1000)

urls.py

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

它会抛出此错误:渲染时捕获NoReverseMatch:Reverse 'cand_resume'的参数'(u'cnds_id',)'和关键字参数'{}'找不到。

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" %}';  

您发送的字符串 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 %}'; 

之类的东西(id从django变化)

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);

或查看此库 https://github.com/mlouro/django-js-utils

这篇关于在javascript中传递反向url中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆