1

I'm using Django, django-storages with S3 (boto) in combination with easy-thumbnails. On my local machine, everything works as expected: if the thumbnail doesn't exists, it gets created and upload to S3 and saves in the easy-thumbnails database tables. But the problem is, when I push the code to my production server, it doesn't work, easy-thumbnails output an empty image SRC.

What I already noticed is that when I create the thumbnails on my local machine, the easy-thumbnail path uses backward slashes and my Linux server needs forwards slashes. If I change the slashes in the database, the thumbnails are showed on my Linux machine, but it is still not able to generate thumbnails on the Linux (production) machine.

The simple django-storages test fails:

>>> import django
>>> from django.core.files.storage import default_storage
>>> file = default_storage.open('storage_test', 'w')

Output: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_FILE_STORAGE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

If I do:

>>> from base.settings import staging
>>> from django.conf import settings
>>> settings.configure(staging)

This works (I have a settings directory with 4 settings files: base.py, staging.py, development.py and production.py)

It seems that on my production server, the config file isn't loaded properly (however the rest of the website works fine). If I add THUMBNAIL_DEBUG = True to my settings file, but easy-thumbnails' debugging still doesn't work (it does work on my local machine).

What can be te problem? I've been debugging for 10+ hours already.

Anoyz
  • 7,431
  • 3
  • 30
  • 35
Peter
  • 1,658
  • 17
  • 23
  • http://stackoverflow.com/questions/12407745/webfaction-django-1-4-1-easy-thumbnails-3-0b-couldnt-get-the-thumbnail-err – catherine Mar 20 '13 at 02:38

3 Answers3

1

Try refactoring your settings to use a more object-oriented structure. A good example is outlined by [David Cramer from Disqus:

http://justcramer.com/2011/01/13/settings-in-django/

You'll put any server-specific settings in a local_settings.py file, and you can store a stripped-down version as example_local_settings.py within your repository.

You can still use separate settings files if you have a lot of settings specific to a staging or review server, but you wouldn't want to store complete database credentials in a code repo, so you'll have to customize the local_settings.py anyways. You can define which settings to include by adding imports at the top of local_settings.py:

from project.conf.settings.dev import *

Then, you can set your DJANGO_SETTINGS_MODULE to always point to the same place. This would be instead of calling settings.configure() as outlined in the Django docs:

https://docs.djangoproject.com/en/dev/topics/settings/#either-configure-or-django-settings-module-is-required

And that way, you know that your settings on your production server will definitely be imported, since local_settings.py is always imported.

krimkus
  • 511
  • 2
  • 8
0

first try to use:

python manage.py shell --settings=settings/staging

to load shell with correct settings file and then try to debug

Alex
  • 1,210
  • 8
  • 15
0

For some reason, S3 and easy thumbnails in the templating language didn't seem to get along with each other ... some path problem which probably could be solved at some point.

My solution (read: workaround) was to move the thumbnail generation into the model inside the image field itseld, for example:

avatar = ThumbnailerImageField(upload_to = avatar_file_name, resize_source=dict(size=(125, 125), crop="smart"), blank = True)

For the sake of completeness:

def avatar_file_name(instance, filename):
    path = "%s/avatar.%s" % (str(instance.user.username), filename.split('.')[1])
    if os.path.exists(settings.MEDIA_ROOT + path):
        os.remove(settings.MEDIA_ROOT + path)   
    return path
seyelent
  • 119
  • 2
  • 7