5

I'm trying to use django-cumulus for serving files off Rackspace CloudFiles. I'm currently only trying it on my local dev server, using Django 1.4.2.

I can use cumulus's syncstatic management command to upload all my static assets successfully, but I can't seem to display them on my site with the same settings.

If my relevant settings are:

STATIC_URL = '/static/'
CUMULUS = {
    'USERNAME': 'myusername',
    'API_KEY': 'myapikey',
    'CONTAINER': 'mycontainername',
    'STATIC_CONTAINER': 'mycontainername',
}
DEFAULT_FILE_STORAGE = 'cumulus.storage.CloudFilesStorage'
STATICFILES_STORAGE = 'cumulus.storage.CloudFilesStaticStorage'

then when I run syncstatic all my apps' static files are uploaded into /mycontainername/static/, as I'd expect. But when I load a page in admin it ignores STATIC_URL and tries to serve assets from URLs like http://uniquekey....r82.cf2.rackcdn.com/path/to/file.css rather than http://uniquekey....r82.cf2.rackcdn.com/static/path/to/file.css.

Also, I can't see how to have my public (non-admin) pages use the static files on CloudFiles, rather than serving them from a local /static/ directory.

Have I missed some crucial setting, or am I doing something else wrong?

Phil Gyford
  • 13,432
  • 14
  • 81
  • 143

1 Answers1

0

I had the same problem. What i did was to

git clone https://github.com/richleland/django-cumulus.git

edit context_processors.py

from django.conf import settings

from cumulus.storage import CloudFilesStorage

def cdn_url(request):
    """
    A context processor to expose the full cdn url in templates.

    """
    cloudfiles_storage = CloudFilesStorage()
    static_url = '/'
    container_url = cloudfiles_storage._get_container_url()
    cdn_url = container_url + static_url

    print {'CDN_URL': cdn_url}

    return {'CDN_URL': cdn_url}

Once you are done, install it with sudo python setup.py install

Do note that context_processors.py from django cumulus is actually quite slow

amdstorm
  • 66
  • 6
  • Thanks amdstorm. Presumably you could get the `static_url` from `settings` instead of hard-coding it. And I'm not sure if you meant to leave the print statement in there :) – Phil Gyford Nov 20 '12 at 13:22
  • Didnt meant to leave the print statement there! sorry! – amdstorm Nov 27 '12 at 03:01
  • i realized when you compile the static asset, the static url is not used, thats why i used it as a /, bad variable naming my bad – amdstorm Nov 27 '12 at 03:01