python – django collectstatic overriding

我正在使用Django 1.3.1和contrib.collectstatic应用来管理我的静态文件.

我的项目结构是

myproject
    - settings.py
    - static-media
    - urls.py
    - media
    - manage.py

其中static-media是包含此项目的静态文件文件夹.在我的settings.py中,我有

PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_PATH,"static")+'/'
STATIC_URL = "/static/"
STATICFILES_Dirs = (
        os.path.join(PROJECT_PATH,'static-media'),)

我正在使用admin_tools来更改管理员的布局.但是我想从admin_tools覆盖特定的css文件(theming.css).所以在我的静态媒体文件夹中我放了admin_tools / css / theming.css.
当我第一次运行python manage.py collectstatic时,它会按预期工作,忽略admin_tools中的认的theming.css并使用我在static-media中定义的那个.不幸的是,如果我再次运行该命令,它会覆盖我的css并添加认值.

这是python manage.py findstatic admin_tools / css / theming.css的输出

Found 'admin_tools/css/theming.css' here:
  /home/paulo/Desktop/Projects/zennetwork/prd/zennetwork/static-media/admin_tools/css/theming.css
  /home/paulo/Desktop/Projects/zennetwork/prd/lib/python2.7/site-packages/admin_tools/theming/static/admin_tools/css/theming.css

任何帮助表示赞赏.谢谢.

解决方法

Django docs只说:

Duplicate file names are by default resolved in a similar way to how template resolution works: the file that is first found in one of the specified locations will be used. If you’re confused,the findstatic command can help show you which files are found.

根据findstatic的输出,第一个应该是您的自定义样式,因此应该是收集的样式.为什么它不这样做是一个谜.

你总是可以明确地忽略其他文件.这有点痛苦,但它会保证你的风格不会被覆盖:

python manage.py collectstatic --ignore site-packages/admin_tools/css/theming.css

如果您还需要忽略其他文件,可以继续添加–ignore< pattern>.不过,这无疑是一个非常可行的长期解决方案.

相关文章

在前一篇博客中我们介绍了加侧旋的乒乓球弧圈技术的模拟,本...
在近期conda的版本更新中,有可能会删除路径下的_sysconfigd...
本文主要展示了一些lambda表达式的使用示例,通过这些示例,...
本文通过对比Jax和Numpy计算Normalized Hamming Distance的过...
我们知道GPU加速在可并行化程度比较高的算法中,能够发挥出比...
Numpy这个库在Python编程中非常的常用,不仅在性能上补足了P...