python - django 不会从 statifiles_dirs 加载静态文件
问题描述
我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/'
,它会完美运行,但我想这不是我稍后将任何其他应用程序添加到项目中的最佳实践。我可能做错了什么?
解决方案
Just change one thing,
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
It will search in static folder inside your app. Also if you want to add a specific directory,
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"), '/your specific directory/',
)
From here you can directly add the particular file name, and djnago will search in that specific directory.
推荐阅读
- python - Pandas:如何将每个数据框行导出到一个新的数据框中?
- php - DIV 在结帐页面(WOO COMMERCE)上生成 2 次?
- excel - Powerquery:如何根据其他行的条件在表中插入一行
- java - 为什么 Android Room @Query LIKE 不返回已知存在的数据
- inheritance - 无法从子类访问伴随对象方法
- c# - 检查网站上的关键字时,循环不会继续运行
- hybris - 已在另一个窗口中登录时出现服务器错误
- javascript - How to test ES6 modules (these with import) with mocha?
- html - 边框只有 div 的一半
- php - 如何在php中的多维数组中搜索针?