Django AWS S3 some media images not showing up
The user uploaded images show up (ex: profile pics) but not my 'static' images (logos). They are both in the same bucket. (Folder -> profile-pics, Folder -> static-images). Heroku production
urls.py
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
settings.py
DEBUG = False
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
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')
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
AWS_S3_REGION_NAME = 'us-west-1'
AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_S3_ADDRESSING_STYLE = "virtual"
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
some template. below isn't loading..
<img src="/media/signin_buttons/btn_google_signin_dark_normal_web.png">
but for example, user uploaded images load up from S3
{{ user.profile_pic.url }}
pip list
asgiref==3.5.2
boto3==1.25.2
botocore==1.28.2
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.7
cryptography==36.0.0
defusedxml==0.7.1
dj-database-url==1.0.0
Django==3.2.15
django-allauth==0.46.0
django-cleanup==5.2.0
django-crispy-forms==1.12.0
django-heroku==0.3.1
django-storages==1.13.1
gunicorn==20.1.0
idna==3.3
jmespath==1.0.1
oauthlib==3.1.1
Pillow==8.3.2
psycopg2==2.9.5
pycparser==2.21
PyJWT==2.3.0
python-dateutil==2.8.2
python3-openid==3.2.0
pytz==2021.1
requests==2.26.0
requests-oauthlib==1.3.0
s3transfer==0.6.0
six==1.16.0
sqlparse==0.4.3
urllib3==1.26.12
whitenoise==6.2.0
<img src="/media/signin_buttons/btn_google_signin_dark_normal_web.png">
This should not be worked.Just follow the instructions blew:
- Add (or use) the
settings.STATIC_URL defined insettings.py. The default path is the folderstatic/in your app folder. - Use
{% load staticfiles %} and{{ static "relative/path/profile.jpg" }}in your template. - Or, You can return the full URL of that image and then set it to
src.
Best of luck :)