Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat am I doing wrong with Django static files?
    text
    copied!<p>I am working on writing a Django app for the first time, so bear with me if I'm a little behind on things.</p> <p>Here is an excerpt from my settings.py:</p> <pre><code>STATIC_ROOT = os.getcwd().replace('\\','/') + '/static' STATIC_URL = '/static_files/' STATICFILES_DIRS = ( os.getcwd().replace('\\','/') + '/static' ) STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ) </code></pre> <p>Note: I'm hoping that the <code>os.getcwd()...</code> line works. I am pretty sure it's not my problem, but please let me know if this is an issue. It's a placeholder for local dev purposes, so don't worry about it remaining there when I deploy.</p> <p>My first issue is that template variables don't seem to be working.</p> <p>An excerpt from my main template file:</p> <pre><code>&lt;link rel="stylesheet" type="text/css" href="{{ STATIC_URL|default:'/static_files/' }}css/base.css" /&gt; </code></pre> <p>I originally just had <code>{{ STATIC_URL }}</code> in there, but that simply returned nothing, so I tried adding <code>|default:'...'</code>. This did successfully generate the given string in the resulting HTML, but still didn't work, which brings me to my second (and more important, honestly) issue.</p> <p>I can't get static files to work at all. I have tried several different methods here. I have tried putting absolute and relative paths (in various combinations) in each of the above <code>STATIC_*</code> variables, I have tried using the equivalent <code>MEDIA_URL</code> vars instead, and I have tried putting the following into my <code>urls.py</code>:</p> <pre><code>urlpatterns = ('', # ... (r'^static_files/(?P&lt;path&gt;.*)$', 'serve', { 'document_root': '/path/to/django/dir/static_files/', 'show_indexes': True } ), ) </code></pre> <p>(I grabbed the above snippet from <a href="http://www.arthurkoziel.com/2008/09/02/handling-static-files-django/" rel="nofollow">http://www.arthurkoziel.com/2008/09/02/handling-static-files-django/</a>.)</p> <p>Now I should note that I will hopefully be eventually serving up static files from a parallel Apache process once initial dev is completed, but I would still really like to know what I'm doing wrong. I haven't been able to find a decently comprehensive tutorial on static files online or on StackOverflow.</p> <p>All help is greatly appreciated.</p> <p><strong>EDIT:</strong> In case it is important, I am on Windows 7 using Python 2.7.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload