0

我有我的网址模式,

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

当我这样做时,在我的模板中

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

它为 css 服务就好了。但是,与 style.css 位于同一目录中的文件 logo.png 在我执行此操作时不会显示:

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

知道为什么吗?

编辑:

它们位于同一目录中: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
4

3 回答 3

0

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/

于 2010-05-30T20:23:19.970 回答
0

很奇怪。运行时返回什么错误代码curl -I http://localhost:8000/logo.png

就在我的脑海中,可能的问题可能是:

  • 错字(在文件名或模板中)
  • 权限
  • 错误数据(它真的是 PNG 吗?它是否以某种方式被清空了?)

此外,urlpatterns您在那里似乎将媒体放在/. 我想这就是你想要的?

于 2010-05-30T19:54:27.987 回答
0

那个 Django 网址对我来说看起来不错。

这两个 curl 请求针对的是 Apache(服务器:Apache/2.2.14 (Ubuntu)),而不是 Django,因此您的 urlpatterns 可能与您看到的错误没有任何关系。您确定 Apache 正在查看该目录而不是其他目录吗?尝试将图像换成不同的图像,看看它是否改变 - 如果没有,你就会知道你的目录路径混淆了。

于 2010-05-31T02:32:55.703 回答