I'm looking for advise on how to structure up my Django project. This is my current structure at the moment:
project_name
- deploy
- app_name
-- migrations
-- templates
-- templatetags
-- __init__.py
-- admin.py
-- context_processors.py
-- defaults.py
-- models.py
-- tests.py
-- views.py
- static
-- admin
-- app_name
--- css
--- fonts
--- img
--- js
--- tinymce
- templates
- project_name
- __init__.py
- fabfile.py
- manage.py
I wonder if it's better to have all the static files in my app folder or should they be like it is at the moment in the static folder and app_name?
Or is it another better way to structure my static files?
Put them in a directory named "static" under your app's directory. That's where django.contrib.staticfiles.finders.AppDirectoriesFinder
looks for them by default.
Inside the static/
directory, create a directory with your app's name.
So on deployment, when you run ./manage.py collectstatic
, Django will copy all the files over to the directory defined in settings.STATIC_ROOT
and each app will have its files inside its own sub-directory.
project_name
- deploy
- app_name
- migrations
...
- static
- app_name
- css
- fonts
- img
- js
- tinymce
- templates
- app_name
- item.html
- list.html
- project_name
- __init__.py
- manage.py
Also, depending on the number of fonts, CSS, and JS files you have, I'd simply put them inside app_name/static/app_name/
and not create another directory level js/
and css/
. "Flat is better than nested", as they say.
If all your point is about static files, by rule of thumb:
They are only tips, but the most-practiced ones. You can place them where you want as long as the path is reachable by Django staticfiles loaders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With