Note: for support questions, please use the cookiecutter-django tag on stackoverflow. This repository's issues are reserved for feature requests and bug reports. If you need quick professional paid support for your project, contact [email protected].
*I'm submitting a ... *
Do you want to request a feature or report a bug?
Greetings.
I'm trying to store static on my VPS, without the help of AWS.
After I run the docker-compose -f production.yml up command, I see a message:
django_1 | 341 static files copied to '/app/habb/staticfiles'.
But, I get a 404 error, for every static file, when I go to the url.
Here are my settings in production.py
STATIC_ROOT = str(APPS_DIR('staticfiles'))
STATIC_URL = '/static/'
MEDIA_ROOT = str(APPS_DIR('media'))
MEDIA_URL = '/media/'
What am I doing wrong ?
caddy_1 | 5.152.1.201 - - [20/Sep/2017:16:07:51 +0000] "GET /static/js/project.js HTTP/2.0" 404 1385
Use project from this repo: https://github.com/narnikgamarnikus/habb
caddy_1 | 5.152.1.201 - - [20/Sep/2017:16:07:51 +0000] "GET /static/js/project.js HTTP/2.0" 200 1385
or
caddy_1 | 5.152.1.201 - - [20/Sep/2017:16:07:51 +0000] "GET /static/js/project.js HTTP/2.0" 302 1385
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
# STORAGE CONFIGURATION
# ------------------------------------------------------------------------------
# Uploaded Media Files
# ------------------------
# See: http://django-storages.readthedocs.io/en/latest/index.html
'''
INSTALLED_APPS += ['storages', ]
AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME')
AWS_AUTO_CREATE_BUCKET = True
AWS_QUERYSTRING_AUTH = False
# AWS cache settings, don't change unless you know what you're doing:
AWS_EXPIRY = 60 * 60 * 24 * 7
# TODO See: https://github.com/jschneier/django-storages/issues/47
# Revert the following and use str after the above-mentioned bug is fixed in
# either django-storage-redux or boto
control = 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIRY, AWS_EXPIRY)
AWS_HEADERS = {
'Cache-Control': bytes(control, encoding='latin-1')
}
# URL that handles the media served from MEDIA_ROOT, used for managing
# stored files.
# See:http://stackoverflow.com/questions/10390244/
from storages.backends.s3boto3 import S3Boto3Storage
StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static')
MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media')
DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage'
MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
# Static Assets
# ------------------------
STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage'
# See: https://github.com/antonagestam/collectfast
# For Django 1.7+, 'collectfast' should come before
# 'django.contrib.staticfiles'
AWS_PRELOAD_METADATA = True
INSTALLED_APPS = ['collectfast', ] + INSTALLED_APPS
# COMPRESSOR
# ------------------------------------------------------------------------------
COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
'''
STATIC_ROOT = str(APPS_DIR('staticfiles'))
STATIC_URL = '/static/'
MEDIA_ROOT = str(APPS_DIR('media'))
MEDIA_URL = '/media/'
Hosting static files outside of AWS S3 is outside the scope of Cookiecutter Django. Therefore, answering this requires paid support. If you are interested in that, please email us for a quote at [email protected].
But my country does not work AWS.
Does this mean that I need to refuse cookiecutter-django?
@narnikgamarnikus, while I sympathize with your plight, the maintainers of this project are unpaid volunteers. Hence why we can't do custom unpaid development whenever someone makes a feature request. However, you can:
Another option to consider is that Digital Ocean now has Spaces, which uses the AWS S3 API, but is on Digital Ocean. See https://blog.digitalocean.com/introducing-spaces-object-storage
I checked the DO Spaces and they have a good solution. The only thing I am not excited about is the pricing. I love AWS "trickle" pricing.
@narnikgamarnikus Did you find the way to use it without Amazon S3 ?
If you select Whitenoise, you don't need AWS S3 for static files, but it's still needed for media files (files uploaded by users).
If your application doesn't use Media, you can deploy your app without any S3 bucket.
Most helpful comment
Hosting static files outside of AWS S3 is outside the scope of Cookiecutter Django. Therefore, answering this requires paid support. If you are interested in that, please email us for a quote at [email protected].