Why won't my CSS, images, and Java script load once my app is deployed on Azure?

Steven hunter 1 Reputation point
2022-10-15T02:17:05.44+00:00

I am using VS code with Django and everything runs fine on my Local server, but once I deploy my app on Azure it wont load any of my images, CSS, and Java script. I am not using whitenoise. I do have my requirements.txt file. I have my allowed_hosts = ["*"]. Any help would be awesome!250659-css.png 250703-static.png

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sreeju Nair 12,666 Reputation points
    2022-10-16T04:38:11.387+00:00

    It seems the server returns html page when requesting style.css, this can be a 404 page or default page. To understand whether the css send correctly, try browsing the css URL directly from the browser address bar.

    for e.g. you may use <<your application address>>/static/style.css to load the style sheet. use this url in browser and see what it returns.

    Hope this helps

    1 person found this answer helpful.

  2. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2022-10-18T13:30:50.757+00:00

    Just adding to sreejukg and DillonJS -- For Django web app which includes static front-end files, kindly check the instructions on Managing static files in the Django documentation

    If you haven’t done this already, kindly try these modifications:

    Oryx runs manage.py collectstatic on your behalf unless you specify the DISABLE_COLLECTSTATIC env var. Make sure you've set STATIC_ROOT in settings.py:

    // settings.py
    STATIC_ROOT = './static/'

    Or

    having STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

    I understand you have mentioned you’re not levering Whitenoise - To host static files in your web app, you may add the whitenoise package to requirements.txt and the configuration for it to settings.py. It specifically serves those files that are found in the folder specified by the Django STATIC_ROOT variable.

    Documentation- Serve static files for Django apps

    Sample - You can find a Django working sample with static files for Web Apps On Linux

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.