【发布时间】:2019-02-23 11:45:50
【问题描述】:
我的style.css 放在appname/static/appname/。
我的settings.py 有这个代码:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static/"),
)
在我的base.html 中,我像这样加载它:
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'appname/style.css' %}">
但是样式没有加载。
如果我删除STATICFILES_DIRS 并将STATIC_URL = '/static/' 更改为STATIC_URL = '/static/appname/',它会完美运行,但我想这不是我稍后将任何其他应用程序添加到项目中的最佳实践。我可能做错了什么?
【问题讨论】:
-
这应该可以,我的意思是你的配置。
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static/"),)行意味着 django 将在目录rootproject/static/中搜索,而不是在您的应用程序中搜索static。你的目录结构是什么?
标签: python css django styles django-staticfiles