无法加载静态文件

时间:2017-08-21 13:39:11

标签: django static

我无法从静态文件夹“todo.js”加载文件。

我的项目树和settings.py:

enter image description here

的index.html

<!DOCTYPE html>
<html>
<head>
    <title>to do</title>
    {% load static %}
</head>
<body>

 <script src="{% static 'js/todo.js' %}" type="text/javascript"></script>
 </body>
 </html>

和控制台给了我以下

[21/Aug/2017 16:36:15] "GET /static/js/todo.js HTTP/1.1" 404 1643

1 个答案:

答案 0 :(得分:0)

STATICFILES_DIRS可以使用,但我建议您在STATICFILES_FINDERS中使用settings.py

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

然后,将您的js目录移到名为todoRest的新目录中(与使用模板的方式相同):

static
  \- todoRest  <- this is the new directory
       \- js
           \- todo.js

希望这有帮助!

相关问题