在文档中https://docs.djangoproject.com/en/dev/howto/static-files/
我读到静态文件应该与各自的应用程序放在一起并调用
{% load staticfiles %}
<img src="{% static "articles/css/base.css" %}" alt="My image"/>
然而,稍后在文档中它提到一些静态文件不属于特定的应用程序。这是哪里STATICFILES_DIRS
发挥作用。如果我读得正确的话STATICFILES_DIRS
是 Django 用于查找其他静态文件的元组。我想知道如何调用从STATICFILES_DIRS
?
例如:类似的东西
<link rel="stylesheet" type="text/css" href="{% static "/css/default.css" %}">
我也不知道该放什么给我STATIC_ROOT
。我要把它留空吗? (''
)
我的项目树
mysite
\articles
\static
\articles
\css
base.css
\static
\images
\css
default.css
\js
\templates
base.html
\settings.py
这是目前在我的 settings.py 中关于静态文件的内容
# looks for static files in each app
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATICFILES_STORAGE = (
'django.contrib.staticfiles.storage.StaticFilesStorage'
)
# the absolute path to the directory where collectstatic will collect static files for deployment (OUTPUT)
STATIC_ROOT = ''
# This setting defines the additional locations the static files app will traverse if the FileSystemFinder finder is enabled.
STATICFILES_DIRS = (
# used for static assets that aren't tied to a particular app
os.path.join(BASE_DIR, 'static'),
)
# URL to use when referring to static files located in STATIC_ROOT
STATIC_URL = '/static/'