Skip to content
Snippets Groups Projects
Commit 4f26b9f2 authored by florimondmanca's avatar florimondmanca
Browse files

store static files on file system again - do not use S3

parent cccaca80
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,10 @@ directories in the S3 bucket (defined by the 'location' below). ...@@ -7,9 +7,10 @@ directories in the S3 bucket (defined by the 'location' below).
from storages.backends.s3boto3 import S3Boto3Storage from storages.backends.s3boto3 import S3Boto3Storage
def StaticBackend(): # uncomment and update aws/conf.py to use for storing static files on AWS
"""Static storage backend.""" # def StaticBackend():
return S3Boto3Storage(location='static') # """Static storage backend."""
# return S3Boto3Storage(location='static')
def MediaBackend(): def MediaBackend():
......
...@@ -9,7 +9,16 @@ import os ...@@ -9,7 +9,16 @@ import os
# Use S3 backends # Use S3 backends
DEFAULT_FILE_STORAGE = 'aws.backends.MediaBackend' DEFAULT_FILE_STORAGE = 'aws.backends.MediaBackend'
STATICFILES_STORAGE = 'aws.backends.StaticBackend' # Uncomment to store static files on AWS
# Beware that Heroku automatically calls 'manage.py collectstatic' for
# each deployment, and this backend does not support checking for pre-existing
# static files on AWS : all the static files will be uploaded on each
# deployment.
# It can be OK to set DISABLE_COLLECTSTATIC on Heroku, but then
# you'd have to run collectstatic manually on Heroku when necessary.
# Since static files on the backend should not change a lot, it seems OK
# to simply use the default file storage for static files.
# STATICFILES_STORAGE = 'aws.backends.StaticBackend'
# Credentials # Credentials
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID') AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
...@@ -32,10 +41,8 @@ AWS_BASE_URL = ( ...@@ -32,10 +41,8 @@ AWS_BASE_URL = (
'https://{bucket}.s3.{region}.amazonaws.com/' 'https://{bucket}.s3.{region}.amazonaws.com/'
.format(bucket=AWS_STORAGE_BUCKET_NAME, region=AWS_S3_REGION_NAME)) .format(bucket=AWS_STORAGE_BUCKET_NAME, region=AWS_S3_REGION_NAME))
# Redefine media and static URLs to upload/retrieve to/from S3 # Redefine media URL to upload/retrieve to/from S3
MEDIA_URL = AWS_BASE_URL + 'media/' MEDIA_URL = AWS_BASE_URL + 'media/'
STATIC_URL = AWS_BASE_URL + 'static/'
# Direct the MEDIA_ROOT and STATIC_ROOT to their bucket directory # Direct the MEDIA_ROOT to its bucket directory
MEDIA_ROOT = 'media' MEDIA_ROOT = 'media'
STATIC_ROOT = 'static'
...@@ -148,14 +148,14 @@ MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS = { ...@@ -148,14 +148,14 @@ MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS = {
} }
# Database # Database
# Will be retrieved through the DATABASE_URL environment variable # Config be retrieved through the DATABASE_URL environment variable
# DATABASE_URL format: postgres://USERNAME:PASSWORD@HOST:PORT/NAME
DATABASES = { DATABASES = {
'default': dj_database_url.config( 'default': dj_database_url.config(
default='postgres://postgres:postgres@localhost:5432/oser_backend_db'), default='postgres://postgres:postgres@localhost:5432/oser_backend_db'),
} }
# Security: SSL and HTTPS # Security
# SECURE_SSL_REDIRECT = True # redirect all to HTTPS
SESSION_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True
SECURE_BROWSER_XSS_FILTER = True SECURE_BROWSER_XSS_FILTER = True
...@@ -194,19 +194,20 @@ USE_I18N = True ...@@ -194,19 +194,20 @@ USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images) and media files (user-uploaded)
# In development, static and media files are tied to the local filesystem. # In development, static and media files are tied to the local filesystem.
# In production, media files cannot be stored on Heroku and need
# to be hosted elsewhere (e.g. AWS S3).
# Storage backend (Django's default) # Static files config
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' STATICFILES_STORAGE = 'django.core.files.storage.FileSystemStorage'
# Static files
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles'), os.path.join(BASE_DIR, 'staticfiles'),
] ]
STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# User-uploaded media files # Media files config
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment