簡體   English   中英

不在Django中渲染的情節

[英]Flot not rendering in Django

我正在嘗試為個人項目學習Django和Javascript / jQuery。 我想用Flot繪制一些數據,我試圖得到一個測試圖,但我似乎做錯了。

在我的base.html我有以下內容在我的head元素中包含jQuery和Flot。

<script src="/site_media/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/site_media/jquery.flot.min.js" type="text/javascript"></script>

在我的inherit.html

{% extends 'base.html' %}

<script type="text/javascript">
alert('Im running!');
$.plot($("#flot-test"), [ [[0, 0], [1, 1]] ], { yaxis: {max: 1 } });
</script>
{% block title %}Detail View for {{ sched_name }}{% endblock %}

{% block content %}
<div id="status_bar">
    <a href="/view_schedules/">{{ user.username }}'s Gradebooks</a> / <a href="/view_schedules/{{ schedule_slug }}/">{{ sched_name }}</a>
</div>

<div id="flot-test" style="width:600px;height:300px">
</div>

The rest concatenated 

但是當我使用Django dev渲染頁面時。 服務器我沒有得到像我包括的警報,情節不呈現。 我得到了一個空白div到我指定的尺寸。 當我在網頁瀏覽器中查看我的頁面源時,它甚至沒有顯示我上面包含的劇情腳本。 我究竟做錯了什么?

JS在呈現目標div之前執行。 您可以在內聯JS之前移動div或將JS調用包裝在document.ready中:

<script type="text/javascript">
$(document).ready(function(){ 
    alert('Im running!');
    $.plot($("#flot-test"), [ [[0, 0], [1, 1]] ], { yaxis: {max: 1 } });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM