Django 文件服务问题

发布于 2024-09-03 16:45:45 字数 1255 浏览 4 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽清梦 2024-09-10 16:45:45

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

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

  • 拼写错误(在文件名或模板中)
  • 权限
  • 错误数据(它真的是 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:

  • 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?

友谊不毕业 2024-09-10 16:45:45

我没有解决手头的问题,但是,我最终能够通过 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/

逆流 2024-09-10 16:45:45

那个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文