【发布时间】:2011-10-28 01:55:51
【问题描述】:
我正在尝试理解django 1.3试图追求的静态结构:
我有一个具有这种结构的项目:
Project
someapp
static
someapp
css
etcetera
models.py
views.py
urls.py
urls.py
manage.py
settings.py
现在我希望覆盖 django admin.. 所以我必须在 settings.py 中设置这些设置,如下所示(basepath 是当前目录的快捷路径):
# 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 = BASE_PATH+'/static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# 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.
)
如果我使用 manage.py 命令 collectstatic,它会按预期将所有静态文件(包括管理文件)收集在“静态”目录中......(在主项目目录中)
但是,在我将该目录添加到 STATICFILES_DIRS 元组之前,它的内容尚未提供,但是我必须更改 STATIC_ROOT 目录设置,否则我会收到错误,它们不能相同...
我认为我忽略了显而易见的事情,因为我必须做的事情似乎是多余的
【问题讨论】:
-
那么.. 你是否将文件实际存储的目录放入
STATIC_DIRS并将STATIC_ROOT指向一个空目录,Django 可以在其中收集静态文件?