3

I'm using the following guide:

https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/

At the section that instructs you on how to "Configuring Django media to use S3". I'm using this for Wagtail.

I'm unclear on where to put the "custom_storages.py" settings. Everywhere I'm putting it doesn't seem to work. I reverted back to Whitenoise for now.

Thanks!

asked Apr 5, 2017 at 15:28
3
  • Just some advice; I followed the same tutorial and have it working, however, the django-storages project is not being actively maintained. I found a bug and issued a PR, but it hasn't been merged or commented on, and it has been quite a few months. Since I was only using S3 and didn't need the other storage types, I switched to using django-s3-storage, which simplifies things significantly and is well documented. You can find it here: github.com/etianen/django-s3-storage Commented Apr 7, 2017 at 12:35
  • @FlipperPA Django-storages is actively maintained, if you look at the commit history you will see updates on an almost daily basis. Commented Apr 7, 2017 at 12:42
  • @dentemm A fair point, I hadn't checked in a bit. But this PR is a fairly major bug fix that has been sitting for a while: github.com/jschneier/django-storages/pull/233 In regards to Wagtail, this causes any user uploaded images / documents in Wagtail to choke since size should be used instead of content_length. Commented Apr 7, 2017 at 21:02

2 Answers 2

3

You can put custom_storages.py anywhere on your Python path. Django will try to find the class using the value of the STATICFILES_STORAGE setting, which in the example is 'custom_storages.StaticStorage'. So Django will, in effect "import custom_storages" and use "custom_storages.StaticStorage" as the storage class. Just make sure you can "import custom_storages" and it should work.

answered Apr 5, 2017 at 18:29
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but can you be a bit more detailed/specific. I'm learning as I go.
Check out how Python finds imported files in your favorite Python reference, and hopefully things will become clear.
For the purposes of settings the path, should I rename the file to not include the .py extension? So it's /x/x/custom_storages. I found this as a guide stackoverflow.com/questions/15109548/…
0

You need to set the STATICFILES_STORAGE setting

STATICFILES_STORAGE = 'path/to/custom_storages.StaticStorage'

If you are using wagtail (which I assume you do since you are tagging this question with it), you can place it in the default home/ directory and refer to it like so: 'home/custom_storages.StaticStorage'

The content of custom_storages.py are stated in the guide you are following:

# custom_storages.py
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage
class StaticStorage(S3BotoStorage):
 location = settings.STATICFILES_LOCATION

Edit: I have a GitHub repo (also a wagtail project) in which I am using this code, but only for my media files. You can check it here.

answered Apr 7, 2017 at 12:50

1 Comment

Thanks you! This helped.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.