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})
This would render the “view.html” template and would give me access to the variables filename, frame_count and folder inside the template, so doing this works perfectly:
<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.
Any idea on what’s happening and how to solve it?
If I understand your question right, then what is happening is that CoffeeScript files aren’t being processed (only your template is being processed and therefore being passed the variables).
If you absolutely need to pass data from backend to frontend in such a fashion you can just use what you have, JavaScript variables will be accessible to you, so if you load your JavaScript below this
<script>tag, you will have access tofile_name,frame_countetc.I’d suggest putting this data in an object, in order to not pollute global namespace with these variables:
And then you can use them with dot notation (also in CoffeeScript):