简体   繁体   English

django 具有多个应用程序的静态文件

[英]django staticfiles with multiple apps

Let's say I have two apps:假设我有两个应用程序:

foo and bar富和酒吧

the project structure like below, how do I make sure app styles do not conflict?项目结构如下,我如何确保应用程序 styles 不冲突? 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运行 manage.py collectstatic 会溶解当前的任一文件...管理应用程序被导入到“管理”文件夹中的收集目录中,但是我的应用程序 static 数据被直接导入到主目录中,因此如果重复文件被覆盖,则覆盖其他应用程序成立

/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

Don't do that this way.不要那样做。 With or without staticfiles/collectstatic, djando would ever serve one of the two style.css files.无论有没有 staticfiles/collectstatic,djando 都可以提供两种style.css文件中的一种。 Just prepend the app name inside static/ .只需在static/中添加应用程序名称即可。 See also how django/contrib/(admin|auth|...)/static are laid out另请参阅django/contrib/(admin|auth|...)/static的布局方式

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM