在django 1.7中包含静态js文件

时间:2014-09-13 10:53:57

标签: javascript django zurb-foundation

以下是settings.py的一部分:

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

HTML模板:

{% load staticfiles %}
...
<head>
    <title>HelpDesk System</title>
    <script scr="{% static "js/vendor/jquery.js" %}" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="{% static "css/foundation.css" %}">
    <script scr="{% static "js/foundation.min.js" %}" type="text/javascript"></script>
</head>
<body>
<script>
    $(document).ready(function() {
        $(document).foundation();
    });
</script>
...
</body>

静态文件夹树:

结果:

Css文件按预期加载,但js确实发生错误并发生错误:Can't find variable: $

1 个答案:

答案 0 :(得分:5)

您的脚本标记看起来包含指定源的错误属性。

<script src="{% static "js/vendor/jquery.js" %}" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="{% static "css/foundation.css" %}">
<script src="{% static "js/foundation.min.js" %}" type="text/javascript"></script>