title: Static files do not load when deployed to Heroku (but does in local server) when DEBUG = false?
body: <p>I've been scouring all over StackOverflow searching for a solution, but none of them seems to be working. I can't get my static files for my Django web app to load when I deploy it to Heroku. It works fine in localhost:8000 though. This is only when I set <code>DEBUG = False</code> . It works fine when <code>DEBUG = True</code>. My static files basically consist of several images for the home page and 1 CSS file. </p>
  
  <p>My main project directory is <em>mynotes</em>.</p>
  
  <p>My app directories are <em>mynotess</em> and <em>users</em></p>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>import os
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = 'w2!3r+pgqz6yhwi_+aw_!-yra7#h69z-n3-ni$gs2v+!!k^2$b'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = False
  
  ALLOWED_HOSTS = ['localhost']
  
  
  # Application definition
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'bootstrap3',
      'mynotess',
      'users',
  ]
  
  MIDDLEWARE = [
      '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',
  ]
  
  ROOT_URLCONF = 'mynotes.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [os.path.join(BASE_DIR, 'mynotes/templates')], #originally empty
          '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 = 'mynotes.wsgi.application'
  
  
  # Database
  # https://docs.djangoproject.com/en/1.10/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/1.10/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/1.10/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/1.10/howto/static-files/
  
  STATIC_URL = '/static/'
  
  MEDIA_URL = '/media/'
  
  LOGIN_URL = 'users/login'
  
  BOOTSTRAP3 = {'include_jquery': True}
  
  if os.getcwd() == '/app':
      import dj_database_url
      DATABASES = {
          'default': dj_database_url.config(default='postgres://localhost')
      }
  
      SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
  
      ALLOWED_HOSTS = ['*']
  
      BASE_DIR = os.path.dirname(os.path.abspath(__file__))
  
      STATIC_ROOT = os.path.normpath(os.path.join(BASE_DIR, 'staticfiles'))
      STATICFILES_DIRS = (
          os.path.join(BASE_DIR, 'static'),
      )
  </code></pre>
  
  <p><strong>urls.py</strong> (from my main project directory - 'mynotes')</p>
  
  <pre><code>from django.conf.urls import include, url
  from django.contrib import admin
  from django.conf import settings
  from django.views.static import serve
  
  urlpatterns = [
      url(r'^admin/', include(admin.site.urls)),
      url(r'^users/', include('users.urls', namespace='users')),
      url(r'', include('mynotess.urls', namespace= "mynotess")), #telling it to look into the urls.py in mynotess for more URLS!
  ]
  
  if settings.DEBUG:
      urlpatterns += [
          url(r'^static/(?P&lt;path&gt;.*)$', serve, {
              'document_root': settings.STATIC_ROOT,
          }),
      ] #I copied (sort of) this from the Django documentations but it still doesn't work.
  </code></pre>
  
  <p>The static files (jpg, png, CSS) are contained within a directory called 'static' in my app directory (<em>mynotess</em>).</p>
  
  <p>Any kind of help will be greatly appreciated. I've tried every solution there is on StackOverflow and none of it seems to work. This works fine when DEBUG is true and only falls apart when DEBUG is false. Even so, it still works on localhost. Am I forgetting to do something here?</p>