开发者

Inserting a JS variable within a Django template tag

This one is a bit tricky for me. I've thus-far resorted to query parameters instead a variable within the {% url %} tag, but I've just got to ask if it's doable:

I'd like to include a JS variable within my template tag. For example:

...
var foo = $(this).attr('title');
$('#bar').load("{% url app.v开发者_Go百科iews.view foo %}");
...

Can it be done?


Not doable. The HTML (and Javascript) are already rendered and served to the client by the time the Javascript is evaluated.

You need some other approach, like (as you mentioned) query parameters:

var foo = $(this).attr('title');
$('#bar').load("{% url app.views.view %}?foo=" + foo);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜