[Answer]-Managing Static Files and Templates Django

1πŸ‘

βœ…

It depends. Since my apps share the same set of static and templates I store them in root dirs:

# Settings
STATIC_URL = '/static/'
STATIC_ROOT = abspath('static')
STATICFILES_DIRS = (abspath('styles'),)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    ...
)

TEMPLATE_DIRS = (abspath('templates'),)
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

# All styles are in one place
β”œβ”€β”€ styles
β”‚Β Β  β”œβ”€β”€ less
β”‚Β Β  β”œβ”€β”€ js

# App's templates are stored in privite dirs so I can move them in app dir any time
# without changing my code: flatpages/flatpage_detail.html Also it works well with
# class based views.
β”œβ”€β”€ templates
β”‚Β Β  β”œβ”€β”€ base.html
β”‚Β Β  β”œβ”€β”€ flaptages/
β”‚Β Β  β”‚Β Β  └── flatpage_detail.html
β”‚Β Β  β”œβ”€β”€ another_app/
β”‚Β Β  β”‚Β Β  └── another_app_detail.html

Then I do manage.py collecstatic and have all static in root/static dir.
It fits me. But if I would make an app to share with community I will put static and templates in it’s own dir as described in docs.

πŸ‘€byashimov

Leave a comment