Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NickMol opened this issue Jan 4, 2024 · 1 comment

Comments

@NickMol
Copy link

NickMol commented Jan 4, 2024

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'
@adamchainz
Copy link
Collaborator

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

This error is from the part of Django that Whitenoise extends, ManifestStaticFilesStorage. It happens when referencing a file that doesn't exist.

Make sure you are running collectstatic on every deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants