Django Static Files - 404

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

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

# URL prefix for static files.
# Example: ""
STATIC_URL = '/static/'

# Additional locations of static files
    # 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.

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.


I figured it out.

I 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.

<?xml version="1.0" encoding="UTF-8"?>
      This removes Helicon Zoo handler and makes IIS processing static files.
      <remove name="django.project#x64" />
      <remove name="django.project#x86" />

try adding {% load staticfiles %} to your template

Need Your Help

Updating Timestamp Fields with Current Time, but not on every row update

php mysql timestamp

I have two TIMESTAMP fields in my user table that I want to update with the current timestamp, one when the row/account is created and the other every time a user logs in.

Why does my function print the correct results, but returns NONE?

python return

In general my code just checks if a value in match1 is greater than a certain value and returned the first pair of values that meet this criteria.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.