I’ve been trying this for about 24 hours now non-stop.
Here’s my settings.py:
import os
from dotenv import load_dotenv
#import django-storages
#import storages.backends.s3boto3
load_dotenv()
DEBUG = False
SECRET_KEY = os.getenv('SECRET_KEY')
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Static settings for S3
STATICFILES_STORAGE = storages.backends.s3boto3.S3Boto3Storage
DEFAULT_FILE_STORAGE = storages.backends.s3boto3.S3Boto3Storage
# These ensure that files are loaded to S3, make sure these values are in place:
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
AWS_S3_REGION_NAME = os.getenv('AWS_S3_REGION_NAME')
# AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
STATIC_URL = f'https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/static/'
MEDIA_URL = f'https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/media/'
#STATICFILES_DIRS = [
# os.path.join(BASE_DIR, 'static'), # Assuming your static files are in a 'static' folder at the root of your project
#]
# Add a proper static root in case of local fallback
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# AWS-specific options
AWS_S3_FILE_OVERWRITE = True
AWS_DEFAULT_ACL = None
AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_QUERYSTRING_AUTH = False # Optional, useful if you want files to be public
#print(f"AWS_ACCESS_KEY_ID: {AWS_ACCESS_KEY_ID}")
#print(f"AWS_STORAGE_BUCKET_NAME: {AWS_STORAGE_BUCKET_NAME}")
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: don't run with debug turned on in production!
ALLOWED_HOSTS = ['*']
INTERNAL_IPS = ['127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp.apps.myappAppConfig',
'storages',
'debug_toolbar',
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
if DEBUG:
MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware')
ROOT_URLCONF = 'myapp.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'myapp.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
##STATIC_URL = '/static'
DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
'debug_toolbar.panels.profiling.ProfilingPanel',
]
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'level': 'DEBUG', # This will log everything at the DEBUG level
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'DEBUG', # Force Django to log everything at DEBUG level
'propagate': True,
},
'storages': {
'handlers': ['console'],
'level': 'DEBUG', # Force storages to log everything at DEBUG level
'propagate': True,
},
'boto3': {
'handlers': ['console'],
'level': 'DEBUG', # Force boto3 to log everything at DEBUG level
'propagate': True,
},
'botocore': {
'handlers': ['console'],
'level': 'DEBUG', # Force botocore to log everything at DEBUG level
'propagate': True,
},
},
}
And when I import my credentials from .env using boto3 and standard script, it seems to connect just fine.
Every time I run collectstatic it’s as if it just skips trying to send it to s3 and goes straight to the STATIC_ROOT. I’ve tried commenting out STATIC_ROOT but then it throws an error about needing it for the static app.
I have absolutely no clue what’s going on here. I can’t find it. I’ve run collectstatic with –clear, checked this over and over from every angle with GPT.
I was previously using whitenoise as an installed app to host images from the server, but that is commented out.
Any ideas?
Every time I run collectstatic it’s as if it just skips trying to send it to s3 and goes straight to the STATIC_ROOT. I’ve tried commenting out STATIC_ROOT but then it throws an error about needing it for the static app.
I have absolutely no clue what’s going on here. I can’t find it. I’ve run collectstatic with –clear, checked this over and over from every angle with GPT.
I was previously using whitenoise as an installed app to host images from the server, but that is commented out.
Any ideas?