覆盖 Django 中特定的管理 css 文件
覆盖管理模板非常简单,只需在模板目录中创建一个文件夹 admin
并将您想要覆盖的任何模板文件复制到其中即可。然而,我只是想使用管理样式表,所以我在静态文件文件夹中创建了一个文件夹 admin
并将 css/base.css
放入其中。与模板解决方案不同,这似乎不起作用。
那么有没有什么方法可以像覆盖模板一样覆盖 django.contrib.admin 的各个 css 文件呢?如果不是,覆盖 css 文件的最佳解决方案是什么?我正在寻找一种解决方案,无需将所有管理媒体文件复制到我的项目中并更改管理的静态目录
Overriding admin templates is as easy as creating a folder admin
in your templates directory and copying whatever template files you'd like to override into it. I simply want to play with the admin style sheets however, so I made a folder admin
in my static files folder and put css/base.css
into it. Unlike the templates solution, this doesn't seem to work.
So is there any way to override individual css files for django.contrib.admin
in the same way that you can override templates? If nay, what would be the best solution for overriding css files? I'm looking for a solution short of copying all the admin media files into my project and changing admin's static directory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我要做的就是重写
base_site.html
模板,如下所示:我将 CSS 放入
blockbots
而不是extrahead
中确保它在最后加载,因此它将覆盖所有其他 CSS。What I'm doing to achieve that is to override
base_site.html
template like this:I put the CSS in
blockbots
instead ofextrahead
to be sure that is loaded at the end, so it will override all others CSS.我认为确实没有其他选择。您将媒体文件复制到新目录中,并在启动服务器时传递
adminmedia
命令行参数,例如在任何情况下,当您在生产服务器上运行它时,必须从以下位置提供管理媒体:一个好的静态服务服务器,您可以为其指定这条新路径。
文档参考: https:// /docs.djangoproject.com/en/1.3/ref/django-admin/#django-admin-option---adminmedia
I don't think there is really an alternative. You copy the media files into a new directory and while you start the server pass the
adminmedia
command line argument, likeIn any case, when you run it on production server, the admin media has to be served from a good static serving server, for which, you can point this new path.
Reference from the Docs: https://docs.djangoproject.com/en/1.3/ref/django-admin/#django-admin-option---adminmedia
也许您可以破解您的 urls.py 文件并仅指向从本地文件夹提供的单个媒体 URL,而其他媒体 URL 从 Django 目录提供(在开发模式下)。
Probably you can hack your urls.py file and point only a single media URL to be served from a local folder while the others are served from the Django directory(in development mode).