I'm running a Django application via Docker. How do I get past the following error message:
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
I do have STATIC_ROOT declared in my settings.py file
import environ
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
env = environ.Env()
env_path = BASE_DIR / ".env"
if env_path.is_file():
environ.Env.read_env(env_file=str(env_path))
...
STATICFILES_DIRS = [BASE_DIR / "static"]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
...
Some web searching led me to believe the settings.py file isn't even being referenced, but I could be wrong. I think that's shown in the manage.py file below.
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_aws.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
The files are created in Windows, but the Docker container is not running Windows. I was getting some errors related to line endings, so I threw in the first 4 lines of this Dockerfile:
FROM ubuntu:latest
RUN apt-get update && apt-get install -y dos2unix
COPY manage.py /manage-clean.py
RUN dos2unix /manage-clean.py && apt-get --purge remove -y dos2unix && rm -rf /var/lib/apt/lists/*
FROM python:3.10-slim-buster
# Open http port
EXPOSE 8000
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV DEBIAN_FRONTEND noninteractive
# Install pip and gunicorn web server
RUN pip install --no-cache-dir --upgrade pip
RUN pip install gunicorn==20.1.0
# Install requirements.txt
COPY requirements.txt /
RUN pip install --no-cache-dir -r /requirements.txt
# Moving application files
WORKDIR /app
COPY . /app
RUN python manage.py collectstatic --no-input
Here's my project directory. Master project is DJANGO-AWS with 2 sub projects django-aws-backend and django-aws-infrastructure.