外部文件Javascript未加载

External file Javascript Not Loading

本文关键字:加载 Javascript 文件 外部      更新时间:2023-09-26

我正在使用django开发服务器学习如何创建模板。但我的本地js文件没有加载。

这是我的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'static目录

在my settings.py文件中:

STATIC_ROOT = 'D:/Test_app/static/'

STATIC_URL = '/static/'

STATICFILES_DIRS =("D:/Test_app/静态)

INSTALLED_APPS = ('django.contrib. ')staticfiles’,…

谁能告诉我如何解决这个问题?提前感谢!

我知道我有点晚了,但另一个可能的解决方案是将<script type="text/javascript" scr="{% static "js/encoder_view.js" %}"></script>中的"scr"更改为"src"

试试:<script type="text/javascript" src="/static/js/encoder_view.js"></script>