2013-06-04 136 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”。