user
user

Reputation: 18529

Django - separating shared & dedicated static files on dev machine

I've gone through https://docs.djangoproject.com/en/dev/howto/static-files/ & related Q&A on stackoverflow regarding placement of static files on Django.

Each project app has its own dedicated js & css files. Plus there are shared js & css files that are common across all apps (e.g. jquery).

 app1
   └── static
         └── app1
              ├── index.js
              ├── index.css
              ├── jQuery.1.10.2.js
              └── jquery-ui-1.10.3\...
 app2
   └── static
         └── app2
              ├── index.js
              ├── index.css
              ├── jQuery.1.10.2.js
              └── jquery-ui-1.10.3\...


Question (specific to a development environment):

  1. Where should I place the jquery & jquery-ui files? The above setup leads to redundancy.

  2. How should I name the dedicated js & css files. I'm asking this because as the project grows, there'll be multiple apps all having an index.js file. It'll be very confusing with 10 index.js files open in an editor. Should I call them app1_index.js?

Upvotes: 0

Views: 140

Answers (1)

Kevin Stone
Kevin Stone

Reputation: 8981

I'd advise creating a "shared" app that holds the common code (I usually name it either common or base).

app1/static
app2/static
common/static

Your other option is to also use both the AppDirectoriesFinder and the FileSystemFinder under STATICFILES_DIR. Here's my setting for this approach (all the os.path stuff just makes the path relative):

STATICFILES_DIRS = (
    os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'base')),
]

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

Regarding naming to avoid collisions. I'd advise using directories in your static assets to differentiate:

app1/static/app1/index.js
ap21/static/app2/index.js

Upvotes: 2

Related Questions