i'm a Django newbie working on my first project and having a problem with static files.
I have created a simple auth system using django.contrib.auth
consisting of two templates: mysite/templates/index.html
and mysite/templates/registration/login.html
. I have global static content in mysite/static
which I want to be able to access on all templates rendered by all apps.
mysite/templates/index.html
contains <img src="{{ STATIC_URL }}pics03.jpg"/>
which renders as "static/pics03.jpg"
and loads fine when I visit the url localhost:8000/
mysite/templates/registration/login.html
contains <img src="{{ STATIC_URL }}pics03.jpg"/>
which also renders as "static/pics03.jpg"
and does not load when I visit the url "localhost:8000/accounts/login/"
In my urls.py I have:
urlpatterns = patterns('',
url(r'^$', 'mysite.views.home'), # plays index.html template
url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
In my settings.py I have:
PROJECT_DIR = os.path.dirname(__file__)
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.
os.path.join(PROJECT_DIR,'static'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_URL = '/static/'
STATIC_ROOT = ''
I was under the impression that Django should be looking for global static content in STATICFILES_DIRS, but it doesn't find the static content for login.html even if I change the url in there to an absolute path to the static folder. Can anyone shed any light on this?