tags:

views:

46

answers:

4

I looked http://docs.djangoproject.com/en/dev/howto/static-files/ already, but am still confused on how to get css/image files loaded.

On my server, the images folder and css file are located at /srv/twingle/search

my urls.py

 1 from django.conf.urls.defaults import *
  2 
  3 # Uncomment the next two lines to enable the admin:
  4 # from django.contrib import admin
  5 # admin.autodiscover()
  6 
  7 urlpatterns = patterns('twingle.search.views',
  8    url(r'^$', 'index'),
  9    url(r'^search/(?P<param>\w+)$', 'index'),
 10 
 11 (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
 12         {'document_root': '/srv/twingle/search'}),
 13 
 14 )

I try to access my css as follows,

<link rel="stylesheet" type="text/css" href="/site_media/style.css" />

That's exactly how the tutorial says to do it, but it doesn't work. Any suggestions?

A: 

You should write the rules directly to the webserver configuration to match the media url. Or use a different vhost for static files.

Not in the django configuration

baloo
+2  A: 

Only use django.views.static.serve for development or testing. By the way, your rule on static files isn't written as an argument for the patterns function. It sould be something like this:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('twingle.search.views',
   url(r'^$', 'index'),
   url(r'^search/(?P<param>\w+)$', 'index'),

   url(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
         {'document_root': '/srv/twingle/search'}),
)   
The MYYN
I copy pasted what you had exactly into urls.py, didn't work
tipu
+3  A: 

You've closed the urlpatterns on line 10, so your site_media declarations are just sitting there, not attached to anything. Get rid of the extra close bracket on 10.

Edited to add You've also used the prefix argument, which is being applied to the static view as well. Do this:

urlpatterns = patterns('twingle.search.views',
   url(r'^$', 'index'),
   url(r'^search/(?P<param>\w+)$', 'index'),
)

urlpatterns += patterns('',
    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': '/srv/twingle/search'})
)
Daniel Roseman
I edited my original urls.py in my post to show you what I put in based on what you said, but still nothing.
tipu
See my update..
Daniel Roseman
Your update worked Daniel, thanks. Can you briefly explain what it is that's going on?
tipu
A: 

maybe you need to check again your path of document root.

eos87