我創建了一個需要來自Django視圖的參數的Django模板。其中一個參數是顯示甘特圖的一點html。它不是將參數渲染爲適當的html,而是將其渲染爲文本。Django模板將HTML參數作爲文本呈現
爲什麼它將參數內容視爲文本而不是識別<script>
和<div>
標籤?
在我傳遞到Django的視圖參數的HTML如下:
: <script language="Javascript" type="text/javascript">
window.onload = function() {
var MyVar = [
{label: "Label-less", times:[{"starting_time":1420228800000,"ending_time":1420257600000}, {"starting_time":1420264800000, "ending_time":1420293600000}, ]},
];
function drawtimeline_MyVar() {
var chart = d3.timeline()
.showBorder()
.stack() // toggles graph stacking
...
*(code removed here for size purposes)*
...
var svg = d3.select("#DIV_MyVar").append("svg").attr("width", 1000)
.datum(MyVar).call(chart);
}
//Call the function
drawtimeline_MyVar();
}
</script>
<div>
<h3>Mehe</h3>
<div id="DIV_MyVar"></div>
</div>
<div id="DIV_MyVar_hover" class="hoverDiv">
<div class="coloredDiv"></div>
<table border=1 cellpadding=10>
<tr>
<td>
<p>Task ID: </p><div id="name"></div>
</td>
</tr>
</table>
</div>
和參數,comm_request,在模板的這樣的狀態下使用
<html>
<head>
<title>Search Results</title>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script language="Javascript" type="text/javascript" src="./Review/d3-timeline-master/src/d3-timeline.js"></script>
<script type="text/javascript">
{{ JSLIB }}
</script>
<STYLE type="text/css">
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 10px;
</STYLE>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>
<p class="text-center">Much Results</p>
</h1>
</div>
</div>
<div class="container">
<h3><p class="text-center">Charts</p></h3>
</div>
<div class="container">
<h4 class="text-center">
Gantt Chart
</h4>
</div>
{{ comm_requests }}
</body>
</html>