Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirements #6

Closed
matheusjardimb opened this issue Dec 11, 2014 · 12 comments
Closed

Requirements #6

matheusjardimb opened this issue Dec 11, 2014 · 12 comments
Labels

Comments

@matheusjardimb
Copy link

Great project!

I've been following django-storages for a while facing the same python3 incompatibility problem. Good to see someone is taking care of the project!

I'm quite new to django, so the answer may be simple: what should I use as requirement? I mean, I need to point to this github repo?

Maybe this is a commom question that may be answered in the README file ;)

Thanks a lot!!

@jschneier
Copy link
Owner

Ah so I'm publishing to pypi under django-storages-redux. I haven't released version 1.2.0 which will be the first with python3 (3.3+) support because while the tests all pass and I am confident that it will work I'd like to actually try it out on a real server pushing to S3 which is something I will be doing tonight on a personal project.

I'll be sure to ping you here when I do publish and will leave this issue open until then.

Also, if you want to install from git in general with pip this reddit post shows you how to do it.

@meshy
Copy link
Contributor

meshy commented Dec 12, 2014

Thank-you very much for taking this upon yourself! Great community spirit!

FWIW, I deployed a website last night (edit: GMT) using the code from master, and it worked fantastically.

The only issue I noticed was a warning generated during pip install due to the MANIFEST.in:

screenshot from 2014-12-12 11 23 05

That's installing on Python 3.4.2 with pip 1.5.4. Thanks again, and well done!

@matheusjardimb
Copy link
Author

@meshy great to see it worked for you! Could you please provide more details about your setup?

I've followed this post (https://ashokfernandez.wordpress.com/2014/03/11/deploying-a-django-app-to-amazon-aws-with-nginx-gunicorn-git/) when creating my project and this lead me to have this at settings:

INSTALLED_APPS += ('storages',)
AWS_STORAGE_BUCKET_NAME = "bucket"
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL

Also, I have 'boto' e 'django-storages-redux' as requirements installed. Unfortunatelly I'm having an error that ends with

...
ImportError: No module named 'storages.backends.s3boto'

What am I missing here?

@meshy
Copy link
Contributor

meshy commented Dec 13, 2014

Could you please provide more details about your setup?

Sure :)

I had to install the (as yet) unreleased version, as the python 3 fixes for the s3boto backend are not included with version 1.1.9:

pip install -e 'git+https://github.com/jschneier/django-storages-redux.git#egg=django-storages-redux'

I then added some code to put static and client media in separate folders in the same bucket:

#core/storage.py
from storages.backends.s3boto import S3BotoStorage

class StaticRootS3BotoStorage(S3BotoStorage):
    location = 'static'

class MediaRootS3BotoStorage(S3BotoStorage):
    location = 'client'

# core/settings.py
INSTALLED_APPS += ('storages',)

STATIC_ROOT = os.path.join(BASE_DIR, 'static_media')
MEDIA_ROOT = os.path.join(BASE_DIR, 'client_media')
STATICFILES_DIR = os.path.join(BASE_DIR, 'core/static')

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')

S3_URL = 'http://{0}.s3.amazonaws.com/'.format(AWS_STORAGE_BUCKET_NAME)
STATIC_URL = os.environ.get('STATIC_URL', S3_URL + 'static/')

DEFAULT_FILE_STORAGE = os.environ.get(
    'DEFAULT_FILE_STORAGE',
    'core.storage.MediaRootS3BotoStorage',
)
STATICFILES_STORAGE = os.environ.get(
    'STATICFILES_STORAGE',
    'core.storage.StaticRootS3BotoStorage',
)
MEDIA_URL = os.environ.get('MEDIA_URL', S3_URL + 'media/')

You'll note that I make a lot of use of environment variables. It's defaulting to production values. In dev, I use:

DEFAULT_FILE_STORAGE='django.core.files.storage.FileSystemStorage' \
STATICFILES_STORAGE='django.contrib.staticfiles.storage.StaticFilesStorage' \
STATIC_URL='/static/' \
MEDIA_URL='/client/' \
DEBUG=1 \
python manage.py runserver

To get the static media onto s3, I ran python manage.py collectstatic on the server as part of the deploy process.

I hope that's enough for you to get it going :).

@jschneier
Copy link
Owner

@meshy great explanation! I will probably steal some of that for when I update the docs if that's okay with you. Just released 1.2 so I'm going to close this issue now.

@meshy
Copy link
Contributor

meshy commented Dec 14, 2014

great explanation! I will probably steal some of that for when I update the docs if that's okay with you.

Thanks :) Please do, that's fine.

Just released 1.2 so I'm going to close this issue now.

Fantastic, thanks!

@matheusjardimb
Copy link
Author

@meshy @jschneier It's working!! Thanks a lot guys! I was struggling with this problem for a long time 😄

@santhu221633
Copy link

@meshy thanks for the work. Its a clear cut explanation. I think there is a typo when you mention

MEDIA_URL = os.environ.get('MEDIA_URL', S3_URL + 'media/')

I think it should be

MEDIA_URL = os.environ.get('MEDIA_URL', S3_URL + 'client/')

@meshy
Copy link
Contributor

meshy commented May 3, 2015

@santhu221633 I think that's just a personal preference for the location of the client media.

@meshy
Copy link
Contributor

meshy commented May 3, 2015

You're right though, it's not very consistent!

@bgarcial
Copy link

bgarcial commented Jan 5, 2016

@meshy I am trying replicate your configuration, and I have the following question if you let me please:

In the
DEFAULT_FILE_STORAGE = os.environ.get( 'DEFAULT_FILE_STORAGE', 'core.storage.MediaRootS3BotoStorage', )

and

STATICFILES_STORAGE = os.environ.get( 'STATICFILES_STORAGE', 'core.storage.StaticRootS3BotoStorage', )

What is the value of the 'STATICFILES_STORAGE' in your os?
core is your name application?

I have the following scheme based in your schema configuration:

STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), )
STATIC_ROOT = os.path.join(BASE_DIR, 'static_media')
AWS_ACCESS_KEY_ID = get_env_variable('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = get_env_variable('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = get_env_variable('AWS_STORAGE_BUCKET_NAME')

S3_URL = 'http://{0}.s3.amazonaws.com/'.format(AWS_STORAGE_BUCKET_NAME)
STATIC_URL = os.environ.get('STATIC_URL', S3_URL + 'static/')

DEFAULT_FILE_STORAGE = os.environ.get( 'DEFAULT_FILE_STORAGE', 'neurorehabilitation.storage.MediaRootS3BotoStorage', )
STATICFILES_STORAGE = os.environ.get( 'STATICFILES_STORAGE', 'neurorehabilitation.storage.StaticRootS3BotoStorage', )

MEDIA_URL = os.environ.get('MEDIA_URL', S3_URL + 'media/')

But, when I run collectstatics, my files always go to STATIC_ROOT value (static_media)
I am a litle confused about of the DEFAULT_FILE_STORAGE and STATICFILES_STORAGE value.

My apologies for the question

@jleclanche jleclanche added s3boto and removed s3boto labels Jun 5, 2017
@algiraldohe
Copy link

I managed to resolve the same issue just using the following parameters:

DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"

# AWS S3 Configuration
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']
AWS_S3_REGION_NAME = 'eu-west-2'


# Only public read for now
AWS_QUERYSTRING_AUTH = False

I changed DEFAULT_FILE_STORAGE from 'storages.backends.s3.S3Storage' >>> "storages.backends.s3boto3.S3Boto3Storage" and it worked for me. This change does not appear on the official documentation.

https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants