0

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?

Community
  • 1
  • 1
user
  • 17,781
  • 20
  • 98
  • 124

1 Answers1

2

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
Kevin Stone
  • 8,831
  • 41
  • 29
  • For the second Q, I'm already using directory names to avoid collisions. My question was from the aspect of usability. In an editor, if I've multiple `index.js` files open, it becomes confusing when switching across files. – user Nov 18 '13 at 07:54
  • Yeah, that can happen. In this case though, why name them all `index`? That's usually just used for examples/tutorials. You should be able to name your scripts/css anything you want and it would be more helpful to name them after their role, like `app1/static/app1/app1.js` – Kevin Stone Nov 18 '13 at 08:25