Django is recommending me that if I am going to only use one server (Apache) to serve both dynamic and static files, then I should serve static files using django.contrib.staticfiles
.
So in my settings.py
I have loaded django.contrib.staticfiles
to my INSTALLED_APPS
and django.core.context_processors.static
to my TEMPLATE_CONTEXT_PROCESSORS
.
I noticed in the admin templates that it links to static files like this (from index.html
):
{% load i18n admin_static %}
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/dashboard.css" %}" />{% endblock %}
But looking at the template tag admin_static
, it's simply a wrapper for static
:
from django.conf import settings
from django.template import Library
register = Library()
if 'django.contrib.staticfiles' in settings.INSTALLED_APPS:
from django.contrib.staticfiles.templatetags.staticfiles import static
else:
from django.templatetags.static import static
static = register.simple_tag(static)
So I concluded that because every admin static file is serverd with a admin/...
prefix, then the full path (for my case) should be
/usr/lib64/python2.7/site-packages/django/contrib/admin/static
So I set that path to my STATICFILES_DIRS
inside settings.py
, but Apache still won't serve any static files (after restating the server). Where did I make a mistake in my logic?