I am using Django 1.3.1 and Python 2.7 on WinVista. I am experiencing the same problem whether on the local dev serer or when deployed to my host.
On the main page of my site static media shows:
http://www.drugpolicyreformmovement.com
On secondary pages CSS, images, etc. do not display:
http://www.drugpolicyreformmovement.com/newsarchive2003
http://www.drugpolicyreformmovement.com/newsarchive2010
or
http://www.drugpolicyreformmovement.com/newsarchive2009
The output of ‘manage runserver’ shows a 404 error for static media on those secondary ‘newsarchive’ pages. Somehow ‘document_root’ is different on a secondary page as opposed to the main page, such that it looks in ‘/newsclippings2003/static’ on those secondary pages instead of just looking in ‘/static’ for everything as it should and like it did for the front page.
I don’t know what of my URLconf is relevant to you so I have included the whole file here:
import os
from django.conf.urls.defaults import *
from django.views.generic import ListView, YearArchiveView
from newsclippings.models import Article
from drugpolicyreformmovement.views import ArticleYearArchiveView
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^$', ListView.as_view(
queryset = Article.objects.order_by("-date", "publication", "author", "headline"),
context_object_name='articles',
template_name='index.html')),
(r'^newsarchive(?P<year>\d+)/$', ArticleYearArchiveView.as_view()),
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{ 'document_root' : os.path.join( os.path.dirname(__file__), 'static') }),
# url(r'^drugpolicyreformmovement/', include('drugpolicyreformmovement.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)
Again, I think this is the problematic line:
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{ 'document_root' : os.path.join( os.path.dirname(__file__), 'static') }),
It doesn’t matter what order I put URLconf entries. This line was designed so I wouldn’t have to make changes when I deploy.
Your url in first page is
in inner page
just add
/in url or use{{ STATIC_URL }}for example
/static/css/blueprint/print.cssor
<img src="{{ STATIC_URL }}css/blueprint/print.css" />just set STATIC_ROOT in settings
see here:
https://docs.djangoproject.com/en/dev/howto/static-files/