Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django staticfiles with multiple apps

Tags:

python

django

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? 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
like image 752
Devon667 Avatar asked Aug 10 '11 12:08

Devon667


1 Answers

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
like image 137
rewritten Avatar answered Oct 24 '22 19:10

rewritten