I am trying to pass a list of HTML (the html construct an interactive graph - ['some html','some html']. Right now, I am having a lot of trouble after exploring several of the following ideas:
- Applying Markup before passing over the list on python side. This words very well if I am passing the HTML list directly to the HTML portion of template
- Applying filters "tojson" and "safe"
- using json.dumps on the python side
- JSON.parse once I did convert it to json
Problems I have been having:
website will actually print out javascript or skip and entire first section of javascript where I had written alerts etc. (This happened when I used just markup and safe).
instead of assigning the graphs into correct div, they just appear randomly after.
graphs display but print out parts of the list that shouldn't have been included as content like "Markup(".
"syntaxError: unexpected token &"
Also trying to display a list of text, website wont display both simultaneously
GOAL: Pass a list of HTML (representing graphs) and a list of text, go through them, assign them to divs with JS, display them side by side. One graph next to one text entry.
code: *looping through list of graph html, and list of text.
<script>
function createDashboard(){
alert("here!");
summaries = {{content|safe}};
summary = document.getElementById('analysis');
for(var i = 0; i < summaries.length;i++){
var div = document.createElement('div');
for (line in summaries[i]){
var para = document.createElement('p');
para.innerHTML = summaries[i][line];
summary.appendChild(para);
}
}
graphs = {{div|safe}};
graph_div = document.getElementById('graph');
for(var h = 0; h < graphs.length;h++){
var div = document.createElement('div');
div.innerHTML = graphs[i];
graph_div.appendChild(div);
}
}
window.onload = function(){
createDashboard();
};
</script>
</html>