views:

55

answers:

3

I have in my url patterns,

urlpatterns += patterns('',
     (r'^(?P<path>.*)$', 'django.views.static.serve',
     {'document_root': '/home/tipu/Dropbox/dev/workspace/search/images'})

In my template when I do

<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}style.css" />

It serves the css just fine. But the file logo.png, that's in the same directory as style.css, doesn't show when I do this:

<img src = "{{ MEDIA_URL }}logo.png" id = "logo" />

Any idea why?

Edit:

Here they are in the same directory: http://i.imgur.com/Wlssb.png

root@tipu_ubuntu:/home/tipu/Dropbox/dev/workspace/search# curl -I http://localhost:8080/logo.png
HTTP/1.1 404 Not Found
Date: Sun, 30 May 2010 19:56:54 GMT
Server: Apache/2.2.14 (Ubuntu)
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=iso-8859-1

root@tipu_ubuntu:/home/tipu/Dropbox/dev/workspace/search# curl -I http://localhost:8080/style.css
HTTP/1.1 200 OK
Date: Sun, 30 May 2010 19:57:06 GMT
Server: Apache/2.2.14 (Ubuntu)
Last-Modified: Thu, 27 May 2010 03:28:14 GMT
Content-Length: 1447
Content-Type: text/css
Vary: Accept-Encoding
Connection: close
A: 

Very strange. What error code is returned when you run curl -I http://localhost:8000/logo.png?

Just off the top of my head, the possible problems could be:

  • Typo (in the file name or in the template)
  • Permissions
  • Bad data (is it really a PNG? Did it get emptied somehow?)

Also, the urlpatterns you've got there seem to put media at /. I presume that's what you want?

David Wolever
I forgot to mention I'm using this through apache's webserver rather than the server django provides
tipu
Ah, well, that might be your problem (although, in production, Apache *should* be serving the static files, not Django). Is the `styles.css` that's being served the correct one?
David Wolever
A: 

I didn't fix the problem at hand, BUT, I was able to end up serving files through apache itself. I used the solution found here: http://oebfare.com/blog/2007/dec/31/django-and-static-files/

tipu
A: 

That Django url looks OK to me.

The two curl requests are hitting Apache (Server: Apache/2.2.14 (Ubuntu)), not Django, so your urlpatterns may not have anything to do with the errors that you're seeing. Are you sure that Apache is looking at that directory and not a different one? Try swapping the image out for a different one and see if it changes - if it doesn't, you'll know that you're getting your directory paths confused.

Anthony Briggs