Solving django-storage NotImplementedError with Amazon S3

Recently I started looking into Amazon’s S3 service to (hopefully) offer better performance on serving up static content for our customers.  Its a great service and ridiculously cheap.  The first client I am applying the S3 storage to is for Dylan Priest Photography, its critical that the images load as fast as possible as that is the main content of his site.  As our web-server is currently a bit overworked off loading the static content to S3 should help with overall performance.

Here at Hardly Code, we are mostly a Django shop.  I found a great plugin called django-storages that has multiple different type of storages.  The documentation is a little bit on the lite side and took a few hours to get the feel for it.  (It was my first time not using the default storage.)

I was applying this to our Album app but when trying to edit an album I kept getting (Creating a new album worked fine):
NotImplementedError: This backend doesn't support absolute paths.
The conflict was in the s3boto storage class the path method was not implemented. As per the Django documentation, for non local storage you should not implement this method.  The only way I found to solve this solution was to go ahead and implement this method in the django-storage code and modify storages.backends.s3boto and add the path method.

def url(self, name):
def path(self, name):
return None

A fairly easy fix and as far as I can tell it hasn’t created any issues with the modification. Not sure if this a bug with django, django-storage, or my implementation, but it took me long enough to figure out that I thought I would document it and hopefully save someone else some time.

11 Responses to Solving django-storage NotImplementedError with Amazon S3

Leave a Reply

Your email address will not be published. Required fields are marked *