The way you are using staticfiles
is slightly incorrect. While I can't tell you exactly what is causing your current situation, I can tell you that your method will cause you headaches in the future. First things first though, I agree with the comments about watching your request traffic in the Django server terminal. Look for 4xx responses and make sure the requested URL is correct. This: /Static/css/photologue/css
has two errors in it.
If you don't want to read further, drop the urls.py static.server line and watch the server terminal. Now, here's how it's all working...
You've got your settings variables correct but you may misunderstand the purpose of STATIC_ROOT. STATIC_URL is the fully qualified or relative URL for your static files. STATIC_ROOT is the folder that will ultimately hold all the static files. It should be empty. Django is responsible for filling it via the manage.py collectstatic
command. The idea is each app in your Django project has its own static/ folder with the js/css/image assets that it needs. In addition, Django will collect the static assets for the Admin and any other third-party packages you use. All of these assets will be organized into your STATIC_ROOT folder. It's not safe to assume files you have their prior to collection will remain.
STATIC_ROOT = '/path/to/empty/static/folder/' # or something dynamic with os.path methods
STATIC_URL = '/static/'
In your case maybe your serenity app has serenity/static/css/serenity.css
and photologue has photologue/static/css/photologue.css
. You could put shared assets in a base/static/
folder.
Now for properly serving static media. Do not use the 'django.views.static.serve'
line in urls.py
. Django's runserver
will automatically serve static files. Behind the scenes it is handling the collectstatic behavior and gathering all your static assets together and serving them up. Using that type of URL pattern in Django 1.3 is unnecessary, a source of confusion, and the kind of thing that will mistakenly go to production. Remember, your webserver (Apache/Nginx) serves static assets. Your Django urls.py files don't need to know a thing about 'em.
Referring to the static URL in templates. You've got /static/
hardcoded in your templates. That will work (but only because STATIC_URL is the same value). To be more flexible about it, you've got three options.
- Use
href="{{ STATIC_URL }}css/photologue.css"
. That variable will be in your templates as long as you include 'django.core.context_processors.static' in your TEMPLATE_CONTEXT_PROCESSORS.
- Use a templatetag:
{% load static %} ... href="{% get_static_prefix %}css/photologue.css"
- In Django 1.4 you'll be able to use
{% load static from staticfiles %}... href="{% static 'css/photologue.css' %}"
It's worth reading up on static files in Django and being aware of the changes coming in Django 1.4