Home:ALL Converter>Django Static Files - 404

Django Static Files - 404

Ask Time:2013-08-23T08:57:06         Author:migreva

Json Formatter

I know there has been a lot of questions on this, but none of them seemed to help me at all. Here's the scenario.

I have a website using the Django Web Framework on IIS on Windows I've been working on. In order to deploy static files, I've been using the collectstatic functionality of the framework to collect the static files. This aspect of it works fine. From my settings.py:

STATIC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static'))

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    'C:/work/wincrash/dev/dev/analysis/static',
)

Running collect static successfully pulls all my static files from C:/work/wincrash/dev/dev/analysis/static and puts them in the /static/ folder in the root directory of the site.

My problem occurs when I'm trying to load the static files on the webpage. Here's a snippet from my base.html page that loads on every page. None of the following static files are loading, failing with the 404 error:

<link type="text/css" href="{{ STATIC_URL }}media/css/custom-theme/jquery-ui-1.8.22.custom.css" rel="Stylesheet" /> 
<script type="text/javascript" src="{{ STATIC_URL }}media/js/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}media/js/jquery/jquery-ui-1.8.22.custom.min.js"></script>

<!-- Base css sheet -->
<link rel="stylesheet" href="{{ STATIC_URL }}media/css/base.css" type="text/css" media="all" />

Which ends up like this when the HTML is rendered:

<link type="text/css" href="/static/media/css/custom-theme/jquery-ui-1.8.22.custom.css" rel="Stylesheet">
<script type="text/javascript" src="/static/media/js/jquery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/static/media/js/jquery/jquery-ui-1.8.22.custom.min.js"></script>
<!-- Base css sheet -->
<link rel="stylesheet" href="/static/media/css/base.css" type="text/css" media="all">

So I guess what I'm asking is what is preventing these files from being loaded? Is it the Django Framework? Is it IIS? The IIS logs are showing the 404 not found for all the static files. Why is this? How does IIS know where to look, and how can I help point it in the right direction?

Thanks for all in advance for your help. I know this might seem like a duplicate question but all the other questions I found on here weren't much help. I've been at this for a while and just would like to move past it.

Author:migreva,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18393073/django-static-files-404
migreva :

I figured it out.\n\nI guess you need a web.config file in your static folder in order for IIS to find the static folder from which to service the static files. When I put a web.config file with the following content in the static folder where I had all the static files, it worked immediately. \n\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<configuration>\n <system.webServer>\n <handlers>\n <!-- \n This removes Helicon Zoo handler and makes IIS processing static files.\n -->\n <remove name=\"django.project#x64\" />\n <remove name=\"django.project#x86\" />\n </handlers>\n </system.webServer>\n</configuration>\n",
2013-08-23T16:59:09
yy