【问题标题】:External file Javascript Not Loading外部文件 Javascript 未加载
【发布时间】:2013-05-30 10:08:24
【问题描述】:

我正在使用 django 开发服务器来研究如何创建模板。但是我的本地 js 文件没有加载。 js 在jsfiddle 中运行良好。

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

在我的 settings.py 文件中:

STATIC_ROOT = 'D:/Test_app/static/'

STATIC_URL = '/static/'

STATICFILES_DIRS = ( "D:/Test_app/static",)

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

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

【问题讨论】:

    标签: javascript django-staticfiles


    【解决方案1】:

    试试这个:&lt;script type="text/javascript" src="/static/js/encoder_view.js"&gt;&lt;/script&gt;

    【讨论】:

    • 感谢吉米,硬编码网址完成了这项工作。我的印象是 {% static "js/encoder_view.js" %} 会自动执行此操作。
    • 您可以查看生成的源代码以检查 url 是否正确组成。
    【解决方案2】:

    我知道我来晚了,但另一种可能的解决方案是将&lt;script type="text/javascript" scr="{% static "js/encoder_view.js" %}"&gt;&lt;/script&gt; 中的“scr”更改为“src”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多