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

Azure app service web application is throwing 500 internal server error when using whitenoise - CompressedManifestStaticFilesStorage and DEBUG = False #481

Closed
karthimalyala opened this issue Mar 10, 2023 · 5 comments

Comments

@karthimalyala
Copy link

karthimalyala commented Mar 10, 2023

Python Version

3.9

Django Version

3.2

Package Version

1.0

Description

In my Django project settings.py file, i am using DEBUG = False and whitenoise to serve my static content on azure app services web application.

When I use the following line which uses CompressedManifestStaticFilesStorage, I am getting 500 internal server error.

STATICFILES_STORAGE = ('whitenoise.storage.CompressedManifestStaticFilesStorage')

I was able to solve this problem by changing the above line to below,

STATICFILES_STORAGE = ('whitenoise.storage.CompressedStaticFilesStorage')

(or)

STORAGES={
    # ...
    "staticfiles": {
        "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
    },
}

I want to understand the rootcause of why it failed with DEBUG = False. We are not getting any error logs as well

With DEBUG = True, I don't see any error, it works fine but as you know it's not recommended to use Debug = True in production systems.

@adamchainz
Copy link
Collaborator

The error may be due to a reference to a static file that doesn't exist in the manifest.

If you aren't seeing an error message in your logs, try configure it so that they do show up. Maybe try Sentry.

@JasonWhisnant
Copy link

I am having the same issue. I followed the troubleshooting and ran "manage.py findstatic --verbosity 2 styles.css" which is the only css file currently referenced in my code. It showed the static file as existing in the correct folder (that was specified by the static_root setting). The error persists. It goes away if I comment out STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'.

I just want to reiterate that this is not due to a reference to a static file that doesn't exist in the manifest. As far as I can tell, the manifest is never created. Logging set up in the settings.py file shows the ValueError that is mentioned in the documentation

@nerdbaggy
Copy link

I am having the same issue, I am still trying to debug it.

When I have the following

STORAGES = {
    "staticfiles": {
        "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
    },
}

All of the template stuff using 'static' generates incorrect URL. With the above example my favicon static url is /favicon.png which causes the 500 error. If I comment out that settings.py section above my favicon is correct at /static/favicon.png

@nerdbaggy
Copy link

I figured it out, if you have a leading / in asset path it will throw the 500 error

Works

{% static "favicon.png" %}

Does not working with the whtienoise static backend, but it does with the built in Django static backend

{% static "/favicon.png" %}

@adamchainz
Copy link
Collaborator

I think this is behaviour from Django's ManifestStaticFilesStorage. As far as the manifest is concerned, the leading / makes it a different path that doesn't exist. We can't fix that here.

This issue was closed.
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

4 participants