Including static js files in django 1.7

时光怂恿深爱的人放手 提交于 2019-12-08 02:16:47

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/25822474/including-static-js-files-in-django-1-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!