Django 文件服务问题
我的 url 模式中有,
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< /a>
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
I have in my url patterns,
urlpatterns += patterns('',
(r'^(?P<path>.*)
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
, 'django.views.static.serve',
{'document_root': '/home/tipu/Dropbox/dev/workspace/search/images'})
In my template when I do
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:
Any idea why?
Edit:
Here they are in the same directory: http://i.imgur.com/Wlssb.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很奇怪。运行
curl -I http://localhost:8000/logo.png
时返回什么错误代码?就在我的脑海中,可能的问题可能是:
另外, urlpatterns< /code> 您似乎将媒体放在
/
处。我想这就是你想要的?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:
Also, the
urlpatterns
you've got there seem to put media at/
. I presume that's what you want?我没有解决手头的问题,但是,我最终能够通过 apache 本身提供文件服务。我使用了这里找到的解决方案:http://oebfare。 com/blog/2007/dec/31/django-and-static-files/
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/
那个 Django 网址对我来说看起来没问题。
这两个curl请求正在攻击Apache(服务器:Apache/2.2.14(Ubuntu)),而不是Django,因此您的urlpatterns可能与您看到的错误没有任何关系。您确定 Apache 正在查看该目录而不是其他目录吗?尝试将图像替换为其他图像,看看它是否发生变化 - 如果没有变化,您就会知道您的目录路径混乱了。
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.