title: Fail to serve static files in deployed Django app (Docker, gunicorn, whitenoise, Heroku)
body: <p>I have built a Django REST API which serves JSON responses only. My problem is, in production (deployed on Heroku with debug=False) the app does not seem to serve relevant static files needed for the proper styling of the admin interface (only use case for static files). Note, in development (localhost with debug=True) the admin interface is properly styled.</p>
  <p>Going to the admin route at the deployed (Heroku) address, the content is delivered but without any styling. The browser developer tools indicate that style sheets could not be loaded due to a 500 error code. Django logging output reveals the below detail.</p>
  <pre><code>django.request ERROR    Internal Server Error: /static/admin/css/base.1f418065fc2c.css
  Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py&quot;, line 47, in inner
  response = get_response(request)
  File &quot;/app/secure_my_spot/custom_middleware/request_logging.py&quot;, line 30, in __call__
  print(f&quot;Content: {response.content}&quot;)
  File &quot;/usr/local/lib/python3.8/site-packages/django/http/response.py&quot;, line 407, in content
  raise AttributeError(
  AttributeError: This WhiteNoiseFileResponse instance has no `content` attribute. Use `streaming_content` instead.
  </code></pre>
  <p>I have gone into the Heroku dyno and verified that the static files, which cause the 500 error, are in fact in the static_root as per Django's settings.py. I have been spending a significant amount of time scouring the internet for clues as to what might cause the files to not be served in production but whatever I have tried, it did not work.</p>
  <p>Below is a curated summary of the relevant files and settings.</p>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM python:3.8-alpine
  
  WORKDIR /app
  
  ENV PYTHONDONTWRITEBYTECODE 1
  ENV PYTHONUNBUFFERED 1
  
  RUN apk update &amp;&amp; apk add \
      gcc \
      libc-dev \
      python3-dev \
      musl-dev \
      postgresql-dev \
      vim \
      bash --no-cache --upgrade
  
  RUN pip install \
      pipenv \
      psycopg2
  
  COPY Pipfile Pipfile.lock ./
  
  RUN pipenv install --system --deploy --pre
  
  COPY . .
  
  RUN python manage.py collectstatic --noinput
  
  CMD gunicorn secure_my_spot.wsgi:application --bind 0.0.0.0:$PORT
  </code></pre>
  <p><strong>heroku.yml</strong></p>
  <pre><code>build:
    docker:
      web: Dockerfile
  release:
    image: web
    command:
      - chmod u+x heroku_entrypoint.sh
  run:
    web: ./heroku_entrypoint.sh
  </code></pre>
  <p><strong>heroku_entrypoint.sh</strong></p>
  <pre><code>#!/bin/bash
  
  python manage.py collectstatic --noinput
  python manage.py migrate --noinput
  gunicorn secure_my_spot.wsgi:application --bind 0.0.0.0:$PORT
  </code></pre>
  <p><strong>settings.py</strong></p>
  <pre><code>BASE_DIR = Path(__file__).resolve().parent.parent
  
  INSTALLED_APPS = [
      &quot;django_extensions&quot;,
      &quot;django.contrib.admin&quot;,
      &quot;django.contrib.auth&quot;,
      &quot;django.contrib.contenttypes&quot;,
      &quot;django.contrib.sessions&quot;,
      &quot;django.contrib.messages&quot;,
      &quot;django.contrib.staticfiles&quot;,
      &quot;rest_framework&quot;,
      &quot;rest_framework.authtoken&quot;,
      &quot;app&quot;,
      &quot;corsheaders&quot;,
  ]
  
  MIDDLEWARE = [
      &quot;corsheaders.middleware.CorsMiddleware&quot;,
      &quot;secure_my_spot.custom_middleware.request_logging.RequestLogging&quot;,
      &quot;django.middleware.security.SecurityMiddleware&quot;,
      &quot;whitenoise.middleware.WhiteNoiseMiddleware&quot;,
      &quot;django.contrib.sessions.middleware.SessionMiddleware&quot;,
      &quot;django.middleware.common.CommonMiddleware&quot;,
      &quot;django.middleware.csrf.CsrfViewMiddleware&quot;,
      &quot;django.contrib.auth.middleware.AuthenticationMiddleware&quot;,
      &quot;django.contrib.messages.middleware.MessageMiddleware&quot;,
      &quot;django.middleware.clickjacking.XFrameOptionsMiddleware&quot;,
  ]
  
  STATIC_URL = &quot;/static/&quot;
  
  STATIC_ROOT = os.path.join(BASE_DIR, &quot;staticfiles/&quot;)
  
  STATICFILES_DIRS = (os.path.join(BASE_DIR, &quot;static&quot;),)
  
  STATICFILES_STORAGE = &quot;whitenoise.storage.CompressedManifestStaticFilesStorage&quot;
  </code></pre>
  <p><strong>wsgi.py</strong></p>
  <pre><code>os.environ.setdefault(&quot;DJANGO_SETTINGS_MODULE&quot;, &quot;secure_my_spot.settings&quot;)
  
  if settings.DEBUG:
      application = StaticFilesHandler(get_wsgi_application())
  else:
      application = get_wsgi_application()
  </code></pre>