Skip to content

Django app on Azure: STORAGES (previously STATICFILES_STORAGE) WhiteNoise variable breaks application #554

@NickMol

Description

@NickMol

Python Version

3.8.10

Django Version

4.2.5

Package Version

6.6.0

Description

I am deploying a Django app on Microsoft Azure App Services and I used Whitenoise for static file handling. My application breaks when I start using the STORAGES variable in my production settings. When I comment this setting out it works perfectly.

I have tried several things:

  • When I replace the STORAGES whitenoise string with the Django string the app works correctly on Azure. So it seems to be a mistake caused by the WhiteNoise setting.
  • When I use whitenoise.storage.CompressedStaticFilesStorage it also works.

Detailed error for the ManifestCompressedStatisFilesStorage is: Missing staticfiles manifest entry for 'admin/css/base.css'

You can find my full code here: https://github.com/NickMol/Django-React-Deploy-Tutorial/tree/main/backend
My deployment settings (deployment.py) are listed down below:

import os
from .settings import * 
from .settings import BASE_DIR

ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']]
CSRF_TRUSTED_ORIGINS = ['https://' + os.environ['WEBSITE_HOSTNAME']]
DEBUG = False
SECRET_KEY = os.environ['MY_SECRET_KEY']

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
]

# CORS_ALLOWED_ORIGINS = [
# ]

STORAGES = {
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
    },
}

#String that does work: "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"


CONNECTION = os.environ['AZURE_POSTGRESQL_CONNECTIONSTRING']
CONNECTION_STR = {pair.split('=')[0]:pair.split('=')[1] for pair in CONNECTION.split(' ')}

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": CONNECTION_STR['dbname'],
        "HOST": CONNECTION_STR['host'],
        "USER": CONNECTION_STR['user'],
        "PASSWORD": CONNECTION_STR['password'],
    }
}

STATIC_ROOT = BASE_DIR/'staticfiles'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions