编辑:
我被关那里咯... STATIC_ROOT指的是目录,Django会收集所有静态文件。 STATICFILES_DIRS是静态文件的搜索路径列表。所以像这样:
settings.py:
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = PROJECT_ROOT + 'static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
"C:/www/django/static",
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
,并添加网址的urls.py:
urlpatterns += staticfiles_urlpatterns()
原来的答案:
这可能是相当混乱。 MEDIA_ROOT目录用于通过文件上传表单上传的文件。对于可由客户端请求直接访问的物理文件(例如样式表,脚本和图像),您必须使用STATIC_ROOT和STATIC_URL。 STATIC_ROOT必须是我认为的绝对路径。
settings.py
# the url: myserver.com/static/
STATIC_URL = '/static/'
# refers to this directory:
STATIC_ROOT = '/home/user/static server files'
让我们说你把你的CSS中的 “/ home/user中/静态服务器上的文件/ CSS /” 然后参考他们这样的:
base.html文件
<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css" />
尝试检查文件的html源代码后,看看“href”指向什么。也许有迹象表明出了什么问题。 – grim