-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added django-storages to serve static and media via bucketeer (s3)
- Loading branch information
Dan Starner
committed
Jan 13, 2022
1 parent
299bbe2
commit 265becc
Showing
7 changed files
with
260 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Django specific | ||
collected-static | ||
collected-media | ||
.vscode | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
{ | ||
"name": "Proper Django Static File Serving", | ||
"description": "Using bucketeer with private/public media and static files in Django", | ||
"repository": "https://github.com/dstarner/django-heroku-static-file-example", | ||
"logo": "https://i0.wp.com/copyassignment.com/wp-content/uploads/2021/08/Django-logo.jpg?fit=474%2C474&ssl=1", | ||
"keywords": ["python", "django", "static"], | ||
"addons": ["heroku-postgresql:hobby-dev"], | ||
"buildpacks": [ | ||
{"url": "https://github.com/moneymeets/python-poetry-buildpack"}, | ||
{"url": "heroku/python"} | ||
], | ||
"env": { | ||
"SECRET_KEY": { | ||
"description": "A secret key value required by Django", | ||
"generator": "secret" | ||
}, | ||
"DEBUG": { | ||
"value": "False" | ||
}, | ||
"DJANGO_SUPERUSER_PASSWORD": { | ||
"description": "Used to generate the superuser of username 'test' (test@example.com)", | ||
"value": "hunter2" | ||
} | ||
} | ||
"name": "Proper Django Static File Serving", | ||
"description": "Using bucketeer with private/public media and static files in Django", | ||
"repository": "https://github.com/dstarner/django-heroku-static-file-example", | ||
"logo": "https://i0.wp.com/copyassignment.com/wp-content/uploads/2021/08/Django-logo.jpg?fit=474%2C474&ssl=1", | ||
"keywords": ["python", "django", "static"], | ||
"addons": [ | ||
"heroku-postgresql:hobby-dev", | ||
{ | ||
"plan": "bucketeer:hobbyist", | ||
"as": "BUCKETEER" | ||
} | ||
], | ||
"buildpacks": [{ | ||
"url": "https://github.com/moneymeets/python-poetry-buildpack" | ||
}, | ||
{ | ||
"url": "heroku/python" | ||
} | ||
], | ||
"env": { | ||
"SECRET_KEY": { | ||
"description": "A secret key value required by Django", | ||
"generator": "secret" | ||
}, | ||
"DEBUG": { | ||
"value": "False" | ||
}, | ||
"DJANGO_SUPERUSER_PASSWORD": { | ||
"description": "Used to generate the superuser of username 'test' (test@example.com)", | ||
"value": "hunter2" | ||
}, | ||
"S3_ENABLED": { | ||
"description": "Enable to upload & serve static and media files from S3", | ||
"value": "True" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.conf import settings | ||
from storages.backends.s3boto3 import S3Boto3Storage | ||
|
||
|
||
class StaticStorage(S3Boto3Storage): | ||
"""Used to manage static files for the web server""" | ||
location = settings.STATIC_LOCATION | ||
default_acl = settings.STATIC_DEFAULT_ACL | ||
|
||
|
||
class PublicMediaStorage(S3Boto3Storage): | ||
"""Used to store & serve dynamic media files with no access expiration""" | ||
location = settings.PUBLIC_MEDIA_LOCATION | ||
default_acl = settings.PUBLIC_MEDIA_DEFAULT_ACL | ||
file_overwrite = False | ||
|
||
|
||
class PrivateMediaStorage(S3Boto3Storage): | ||
""" | ||
Used to store & serve dynamic media files using access keys | ||
and short-lived expirations to ensure more privacy control | ||
""" | ||
location = settings.PRIVATE_MEDIA_LOCATION | ||
default_acl = settings.PRIVATE_MEDIA_DEFAULT_ACL | ||
file_overwrite = False | ||
custom_domain = False |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters