【发布时间】:2018-11-16 10:13:54
【问题描述】:
这是我的目录结构
app_web
_init_.py
settings.py
urls.py
wsgi.py
upload_app
migrations/
static/
js/
alert.js
templates/
upload.html
_init_.py
admin.py
apps.py
models.py
tests.py
views.py
db.sqlite3
manage.py
在 settings.py 中,我的
STATIC_URL = '/static/'
在我的 upload.html 中
{% load staticfiles %}
<script type="text/javascript" src="{% static "js/alert.js" %}"></script>
它不起作用,每次都会抛出 404 错误。我什至尝试过load static,但它仍然无法从静态文件夹加载任何内容并引发 404 错误。
我使用的是 Windows 10 机器和 Django==1.9
【问题讨论】:
-
对不起,
{% load static from staticfiles %}。 -
@WillemVanOnsem 它抛出错误
'staticfiles' is not a valid tag or filter in tag library 'static' -
虽然
django.contrib.staticfiles存在于 settings.py 中 -
您是否在设置中添加了 STATICFILES_DIRS?
-
修复了,你能不能看看我的回答并根据它提供建议@leelum1
标签: django django-models django-templates