Cookiecutter-django: static files in production without AWS

Created on 20 Sep 2017  路  7Comments  路  Source: pydanny/cookiecutter-django

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 ... *

    • [ ] bug report
    • [ ] feature request
    • [ ] support request => Please do not submit support request here, see note at the top of this template.
  • 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 ?

  • What is the current behavior?

caddy_1 | 5.152.1.201 - - [20/Sep/2017:16:07:51 +0000] "GET /static/js/project.js HTTP/2.0" 404 1385

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Use project from this repo: https://github.com/narnikgamarnikus/habb

  • What is the expected behavior?

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/'



  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

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].

All 7 comments

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:

  1. Create a Cookiecutter Django fork with the changes you require and pull from upstream periodically.
  2. Request professional support from [email protected]

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.

Was this page helpful?
0 / 5 - 0 ratings