Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named custom storages - django-storages boto

I am trying to follow this tutorial for using s3 but pretty much until the last step, somehow I get this error and I am not sure where I should import my own customed module

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

Everything is fine, that I am able to upload / copy / use the static files using s3 then the step about creating custom storage for media usage

# custom_storages.py
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage

class StaticStorage(S3BotoStorage):
    location = settings.STATICFILES_LOCATION

I created that .py file inside the same directory as the setting.py (setting.py where it included INSTALLED_APPS and more)

then inside the setting I added below as mentioned on the tutorial

STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)

then I ran python manage.py collectstatic

I get this error

  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named custom_storages

Can someone give me a hand? Thanks in advance.

like image 930
Dora Avatar asked Feb 03 '17 01:02

Dora


2 Answers

This credit should go to Shubham Namdeo who gave me the link of https://disqus.com/home/discussion/wwwcaktusblog/using_amazon_s3_to_store_your_django_sites_static_and_media_files/

well there are lots of suggestions and ways / errors people found which helps but as for me the part that helped me solve this problem is just move the custom_storage.py into the same directory as the manage.py so manage.py and custom_storage.py are actually in the same level of the directory structure then it all works just like that~

Don't even need to import anything.

I have attached an image of the part where I got my answer so you don't have to scroll all the way down if you have the same problem as mine.

s3

like image 169
Dora Avatar answered Sep 29 '22 12:09

Dora


in my project i have the custom_storages inside a folder and that works maybe moving it might help?

STATICFILES_STORAGE = 'myapp.custom_storages.StaticStorage'

the folder structure looks like this

/myproject
   someapp1/
   someapp2/
   myapp/
      settings/
         __init__.py
         production.py
      custom_storages.py
   manage.py
like image 36
davidejones Avatar answered Sep 29 '22 13:09

davidejones