Media files are not loading in the website.. How to find the path to the media files in django project deployed on azure?

Adarsh NA 0 Reputation points
2024-04-29T02:33:50.6233333+00:00

logs.png ui .png

As shown in images, on the webapp deployed on azure, images are not loading. in local, it is stored in media folder of the django application and working fine. We have used CI/CD through Git Actions for deployment. Frontend is using react and back end is using django.

  1. Why images are not loading after deployment when it is working fine in local?
  2. Where can we see the media folder in azure dashboard?
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,984 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
776 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 22,766 Reputation points Microsoft Employee
    2024-05-01T12:53:20.0733333+00:00

    @Adarsh NA , Thanks for reaching out. I’m sorry to hear that you’re having trouble with media files in your Django project deployed.

    1. If you haven't done, you may leverage App Service diagnostics from Azure Portal> Navigate to your App Service app in the Azure Portal. In the left navigation, click on Diagnose and solve problems - Review - “Configuration and Management to fetch more details.
    2. Browse to Kudu : http://”yoursitename”.scm.azurewebsites.net.
      (for access the Kudu /media folder)
    • Example: if your Azure App Service Web App name is “testwebapp”, then surf to http://testwebapp.scm.azurewebsite.net
    • Click ‘Debug Console’ and select ‘CMD’
    • Traverse to wwwroot folder
    1. Enable and review logs to fetch more details about the error: troubleshoot-diagnostic-logs#access-log-files

    If you haven't done this already so, for App service (Windows).

    1. Set default list of MIME types: Media Files - HTTP 404 - Azure App Service on Windows

    5.Use below line of code(at D:\home\site\wwwroot using kudu console) to generate static file folder in Django app.

    • -Add/Once you have static folder in D:\home\site\wwwroot folder.
    • -Navigate to Azure Portal and add a new section in Virtual application and directories under Application Settings with below values
    • -Navigate to D:\home\site\wwwroot\static folder and add web.config file with below
    • D:\home\site\wwwroot\static\web.config content
    <?xml version="1.0"?>  
    <configuration>  
        <system.webServer>
            <handlers>
               <clear />
                <add 
                    name="StaticFile"
                    path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" 
                    resourceType="Either" 
                    requireAccess="Read" />
            </handlers>
        </system.webServer>
    </configuration>  
    
    

    Django app with HttpPlatformHandler in Azure App Services (Windows)

    Kindly let us know how it goes, I'll follow-up with you.


     If the answer helped (pointed, you in the right direction) > please click Accept Answer - it will help users to find the answers quickly.

    0 comments No comments