question

ehoke-9432 avatar image
0 Votes"
ehoke-9432 asked ajkuma-MSFT answered

500 Server Error on Django on App Service when Debug=False

When I set Debug=False in my django app deployed to Azure App Service I get a 500 Server Error whenever I try to navigate to any of API pages or the admin panel. The application still works fine, I have a React front end that is still connected to the API however I cannot access API pages directly. Looking at SE I found that this was a common problem for Heroku users but not for Azure and I made some adjustments to my code that unfortunately didn't really help. I have two questions:

  1. Has anyone run into this issue before on Azure?

  2. One of the solutions that was recommended for Heroku users was to comment out the following line in production.py
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    I am a bit hesitant to do this since I don't want to mess up the build sequence, but has anyone tried this method and gotten it to work without ruining their deployment?

azure-webapps
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ehoke-9432,

You may try turning it off by modifying it to DEBUG = os.environ[‘DEBUG’] and set the following in your App Settings under the configuration blade in the Azure Portal ( see if this makes any difference)


key: DEBUG
value: 0


As mentioned in the doc, In your settings.py file, you need add the following line for Whitenoise:
STATICFILES_STORAGE = ('whitenoise.storage.CompressedManifestStaticFilesStorage')

Production settings for Django apps

I'm not sure about the Heroku issues that you have called-out.
When you say, 'I found that this was a common problem for Heroku users but not for Azure', If I understand you correctly - Typically, if the app doesn't work locally, in most cases it also doesn't work on Azure.

Kindly let us know how it goes. If the issue still persist, I'll follow-up with you privately.

0 Votes 0 ·

I am going to be honest this is not particularly helpful. I have set these variables as described, except I keep them in production.py which are the production settings (and how MS structures its sample django app).

The app works perfectly locally this issue is clearly because of an interaction with whitenoise (which is only used in production settings) there is some issue with it serving static files properly. I mentioned Heroku because this exact issue is quite common on their platform (and is specifically related to the use of Whitenoise to compile static files. One common workaround on that platform is to eliminate the setting:
STATICFILES_STORAGE = ('whitenoise.storage.CompressedManifestStaticFilesStorage')

I guess the most direct and relevant question is what happens if I do this to my build sequence? Will it not work properly? Is there some other configuration to make this usable.

0 Votes 0 ·

@ehoke-9432, Apologies for any confusion! Thanks for sharing additional details on this.
While I'm checking on this internally. I'll wish to connect with you offline to provide focused assistance.

0 Votes 0 ·

1 Answer

ajkuma-MSFT avatar image
0 Votes"
ajkuma-MSFT answered

Posting our offline discussion to benefit the community.

Using the settings should not affect the build sequence if you are using Oryx to build the app, this also depends on app service configurations and deployment method.
Based on the doc of WhiteNoise, removing the line will disable WhiteNoise module used to serve static files, performance might suffer as WhiteNoise is used to enhance static content performance on Python.

https://github.com/projectkudu/kudu/wiki/Configurable-settings#enabledisable-build-actions
SCM_DO_BUILD_DURING_DEPLOYMENT=true – With this setting set to true - Kudu will execute build steps on your site during deployment.

Oryx attempts to build and run Django apps appropriately – Best practices tips for Django apps.
https://github.com/microsoft/Oryx/wiki/Django-Tips

Thanks again for your patience and cooperation, @ehoke-9432

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.