IIS django static files not showinvg

i try to deploy my Django app on IIS for work but is not serving my static files. i watched this tutorial: https://www.youtube.com/watch?v=APCQ15YqqQ0.

Right now my Django app looks like this, the CSS is not appearing enter image description here

I added a virtual directory as well and have set the physical path to the static file in the project. enter image description here

In my my settings.py i have

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

I have no idea what i am missing. please tell me if you need more information.

Change the

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

to

STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'

That should fix OP's Internal error 500 when requesting the files.

Additionally, as @LexLi mentions

wfastcgi is deprecated, so that's no longer the right way to host Python web apps on IIS. You might switch to HttpPlatformHandler

You can refer to the following steps to host a Django web application using Httpplatformhandler.

For Django physical path is a path to manage.py of your application.

Download and Install Httpplatformhandler on IIS using Windows Platform Installer. Or download from this link.

Django APP with Httpplatformhandler Add web.config where your Django app is defined.

    <?xml version="1.0" encoding="UTF-8"?>
     <configuration>
         <system.webServer>
             <handlers>
                 <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"
 requireAccess="Script" />
             </handlers>
             <httpPlatform startupTimeLimit="10" startupRetryCount="10" stdoutLogEnabled="true"
 processPath="C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe"
 arguments="manage.py runserver">
                 <environmentVariables>
                     <environmentVariable name="foo" value="bar"/>
                 </environmentVariables>
             </httpPlatform>
         </system.webServer>
     </configuration>

HttpPlaform is handling the Python process. ProcessPath is a physical path to python executable. Just like you provide python path in a windows environment variable. To access the python executable. Here you have to provide python.exe in processPath.

Arguments are the same argument you pass running any python web application. For eg. python manage.py runserver where app.py to port number all are arguments. In the above application, manage.py runserver is passed to run Django application.

Add Permission to Django Application and Python folder where your executable is present.

  1. Open folder properties.

  2. In Security click on Edit then click on Add

  3. Enter object name as IIS AppPool<yourappname>

  4. Click on the check name if its present click ok and allow permissions you wanted to give then apply it.

Run your application

For more information, please refer to this tutorial.

Back to Top