2013-06-04 138 views
1

我使用django開發服務器來研究如何創建模板。但我的本地js文件沒有加載。 js在jsfiddle中工作正常。外部文件Javascript未加載

這是我的html文件。

{% load staticfiles %} 
<!DOCTYPE html> 
<html> 
<head> 
<title>Test</title> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
<link rel="stylesheet" type="text/css" href="{% static "css/encoder_view.css" %}" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
<!--This external file--> 
<script type="text/javascript" scr="{% static "js/encoder_view.js" %}"></script> 

</head> 
<body> 
<table> 
<tr id="top-border">  
    <td width="120">  
    <input id="check-all" class="checkbox" name="selector" type="checkbox" style="width:15px;"/> 
    <span id="testcheck">Check All</span> 
    </td>  
</tr> 
</table>  
</body> 
</html> 

Thomas Orozco指令 和使用manage.py collectstatic我所有的靜態文件後,現在是在d:\ Test_app \靜態 目錄

在我的settings.py文件:

STATIC_ROOT =「d:/Test_app /靜態/」

STATIC_URL = '/靜態/'

STATICFILES_DIRS =( 「d:/ Test_app /靜」)

INSTALLED_APPS =( 'django.contrib.staticfiles',...

誰能給我方向如何解決這個問題。提前致謝!

回答

0

試試這個:<script type="text/javascript" src="/static/js/encoder_view.js"></script>

+0

感謝吉米,硬編碼的網址做了這項工作。我印象中{%static「js/encoder_view.js」%}會自動執行此操作。 – Charlesliam

+0

您可以查看生成的源代碼以檢查URL是否正確組合。 – ryanjdillon

+0

https://github.com/oyvindkinsey/easyXDM – internety

1

我知道我有點晚,但另一種可能的解決方案,這將是<script type="text/javascript" scr="{% static "js/encoder_view.js" %}"></script>改變「SCR」到「SRC」。