English 中文(简体)
Django + Coffescript: Django 模板中的变量
原标题:Django + Coffescript: Django variables in templates

In django, I can render a html template from a view action like this:

return render_to_response( video_handle/view.html , { filename : filename, 
 frame_count : frame_count,  folder : folder})

这将使“观点.html”模板成为可能,使我能够查阅模板内的变数文档名称、框架_对面和夹,这样就能够很好地做到:

<script type="text/javascript">
file_name =  {{filename}} 
frame_count =  {{frame_count}} 
folder =  {{folder}} 
</script>

Now, when i try the same in a coffescrip file, compile the file to javascript and load it to my view.html template, the values of python s variables are not assigned to javascript variables and instead, these variables keep the string value meaning that form example file_name variable keeps the value of this string {{filename}} instead of the actual value of the python s variable called filename.

任何关于发生什么和如何解决这一问题的想法?

最佳回答

如果我理解你的提问权,那么正在发生的情况是,正在处理咖啡版文档(只有你的模板正在处理之中,因此通过变量)。

如果你绝对需要以这种方式将数据从背后传送到前线,那么 Java的文字变数将提供给你,这样,如果你把 Java的文字载在<条码>和代号”;标签,你将可检索<条码>:姓名、<条码>>>_count等。

我建议把这一数据放在一个目标上,以便不以这些变量污染全球名称空间:

<script>
var options = {
  fileName :  {{file_name}} ,
  frameCount :  {{frame_count}} 
  // more options here
};
</script>

然后,你可以使用 do(也在咖啡厅):

alert options.fileName # should alert the file name
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签