加入收藏 | 设为首页 | 会员中心 | 我要投稿 大庆站长网 (https://www.0459zz.com/)- 科技、智能边缘云、事件网格、云计算、站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python C django collectstatic overriding

发布时间:2023-12-17 00:46:32 所属栏目:Python 来源:DaWei
导读: 我正在使用Django 1.3.1和contrib.collectstatic应用来管理我的静态文件.

我的项目结构是

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

我正在使用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

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

(编辑:大庆站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章