1

Is it possible to have static files only in PROJECT_DIR/static directory without duplicates of static files in app dirs and without needing to do collectstatic command? On local computer Django dev server is used, in production - some other web server. From what I have read so far I decided that it's impossible, but maybe it's not true.

DSblizzard
  • 4,007
  • 7
  • 48
  • 76

1 Answers1

6

Of course it's possible.. the static files app is there to be useful. If you dont like "duplicates" (that's the whole point - you can have files per app, all merged into one area), don't use the staticfiles app.

Just use any folder, anywhere, as your assets folder. In production, serve it at some url, say MY_URL. In development, wire up your URLConf to serve files at your asset folder at MY_URL

https://docs.djangoproject.com/en/1.5/howto/static-files/#serving-files-uploaded-by-a-user

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # ... the rest of your URLconf goes here ...
) + static('MY_URL', document_root='path-to-my-files')

This is the old school method of doing this, before staticfiles brought its goodness.

Are you sure you can't solve this problem by just using the staticfiles app? It's not much work to add in a python manage.py collectstatic --noinput in your deployment script.

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245
  • I added import and "+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)" to urlpatterns, but css does not load (from app subdir it loads fine). What else can be missed? – DSblizzard May 30 '13 at 07:27
  • I would not do that, as your goal is to not use staticfiles at all.. but then files from settings.STATIC_ROOT will be available at settings.STATIC_URL in development. That is automatic anyways.. default runserver in development does exactly that. – Yuji 'Tomita' Tomita May 30 '13 at 07:29
  • I forgot to comment out 'django.contrib.staticfiles', in INSTALLED_APPS – DSblizzard May 30 '13 at 07:37