Anatoly Maltsev
Anatoly Maltsev

Reputation: 77

Including static js files in django 1.7

Here is part of settings.py:

STATIC_URL = '/static/'

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

HTML template:

{% 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>

Static folder tree:

Result:

Css file loads as expected, but js does't and error occurs: Can't find variable: $

Upvotes: 3

Views: 15119

Answers (1)

schillingt
schillingt

Reputation: 13731

It looks like your script tags contain the wrong attribute for specifying the source.

<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>

Upvotes: 8

Related Questions