0

I have all of my static images served locally on my Django website project. I need them to be hosted on AWS for my DEBUG = False to work. I have followed many tutorials on how to do this and have had no luck. I have posted my code below for a last-ditch effort hoping that it is just something I have missed. I have my AWS bucket currently as public because that's what I have seen others doing. Any help is greatly appreciated. Thanks!

setings.py

AWS_ACCESS_KEY_ID = 'hidden for privacy'
AWS_SECRET_ACCESS_KEY = 'hidden for privacy'
AWS_STORAGE_BUCKET_NAME = 'hidden for privacy'

AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Caracas'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')

#MEDIA_URL = '/images/'
#MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images/')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, '..','www','media')

HTML

{%  load static %}
<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="shortcut icon" type="image/x-icon" href="{% static 'tab_icon.ico' %}">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="{% static "css/side.css" %}">
  <link rel="stylesheet" href="{% static "css/style.css" %}">
  <link rel="stylesheet" href="{% static "css/materialize.css" %}">
  <link rel="stylesheet" href="{% static "css/front_page.css" %}">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>

<body>
<nav class="blue hide-on-med-and-down banner">
  <div class="nav-wrapper">
    <a href="/front_page" class="header__name"><img src="{% static 'logo_name.png' %}"></a>
  </div>
</nav>
</body>

My bucket structure is bucketname/ images/ all of my static files.

My static files work fine when served locally but when I take them off to have AWS take over they show nothing on screen and "inspect" shows a small url to where they should be locally instead of a long user from s3 and AWS. I am knew to AWS. Thank you for any help!

Russell Hertel
  • 121
  • 3
  • 14
  • Are boto3 and django-storages installed in your venv? Have you run collectstatic? – hd1 Aug 27 '21 at 00:26
  • @hd1 Yes I have and I'm getting the same results. My staticfiles are all in a file called static and not staticfiles. Could that be a problem? – Russell Hertel Aug 27 '21 at 01:28

0 Answers0