带有多个应用程序的Django静态文件 [英] django staticfiles with multiple apps

查看:30
本文介绍了带有多个应用程序的Django静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个应用程序:

Let's say I have two apps:

foo和bar

如下所示的项目结构,如何确保应用程序样式不冲突?运行manage.py collectstatic可以溶解当前文件中的任意一个...管理应用程序被导入到"admin"文件夹中的收集目录中,但是我的应用程序静态数据被直接导入到主目录中,因此如果重复文件被覆盖,则其他应用程序将被覆盖找到

the project structure like below, how do I make sure app styles do not conflict? Running manage.py collectstatic dissolves either one of the files currently... The admin app is imported to the collected directory within an 'admin' folder however my app static data gets imported directly into the main directory thus overwriting other apps if duplicate files are found

/Project
   /foo
      /static
         /css
            /style.css
      /views.py
      /models.py
      /urls.py
   /bar
      /static
         /css
            /style.css
      /views.py
      /models.py
      /urls.py
   /urls.py
   /manage.py
   /settings.py

推荐答案

不要这样.不论是否带有staticfiles/collectstatic,djando都将服务于两个 style.css 文件之一.只需在 static/中添加应用名称即可.另请参见 django/contrib/(admin | auth | ...)/static 的布局

Don't do that this way. With or without staticfiles/collectstatic, djando would ever serve one of the two style.css files. Just prepend the app name inside static/. See also how django/contrib/(admin|auth|...)/static are laid out

Project
|-- foo
|   |-- static
|   |   `-- foo
|   |       `-- css
|   |           `-- style.css
|   |-- views.py
|   |-- models.py
|   `-- urls.py
|-- bar
|   |-- static
|   |   `-- bar
|   |       `-- css
|   |           `-- style.css
|   |-- views.py
|   |-- models.py
|   `-- urls.py
|-- urls.py
|-- manage.py
`-- settings.py

这篇关于带有多个应用程序的Django静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆