使用django服务器但未在网页上显示的图像

时间:2013-09-14 16:06:18

标签: django

我正在创建一个网站,一切正常,直到昨天网页上的图像突然停止显示。服务器似乎获取图像,但它们没有显示,我无法弄清楚原因。当我加载网页时,我得到了一个占位符,就像它要加载一样,然后就消失了。

这些是我的配置:

settings.py

CACHES = {
    'default' : {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}

MEDIA_ROOT = '/home/hammad/virt_env/virt1/gccFishing/media'

MEDIA_URL = '/media/'

我正在使用sorl-thumbnail,一个用于显示图像的django包。使用它,我在这样的模板中显示图像:

template.html

{% load thumbnail %}


{% thumbnail  user.image "200x200" crop="center" as im %}
       <img src="{{im.url}}" width="{{ im.width }}" height="{{ im.height }}">
    {% endthumbnail %}  

当我加载网页时,这些是服务器消息:

[14/Sep/2013 15:41:45] "GET / HTTP/1.1" 200 159218
[14/Sep/2013 15:41:45] "GET /media/cache/c0/17/c017021609e735bdc53f402ae6009bae.jpg HTTP/1.1" 200 155657
[14/Sep/2013 15:41:47] "GET /saudi-arabia/ HTTP/1.1" 200 284186
[14/Sep/2013 15:41:47] "GET /media/cache/e9/25/e925347688cc973ecc997f00b6ee0b83.jpg HTTP/1.1" 200 156198
[14/Sep/2013 15:41:47] "GET /media/cache/a4/ac/a4aca3c7a23aeada770062e9519a8daa.jpg HTTP/1.1" 200 156731
[14/Sep/2013 15:41:47] "GET /media/cache/0a/21/0a2118ecac84d6451f3dd39cd881d8bb.jpg HTTP/1.1" 200 156728

在重新启动计算机之前,图像工作正常。重新启动后,这个问题开始了,随着这个问题,我开始收到这些错误:

[14/Sep/2013 15:41:48] "GET /media/cache/0a/21/0a2118ecac84d6451f3dd39cd881d8bb.jpg HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 46531)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/hammad/virt_env/virt1/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 150, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 651, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 710, in finish
    self.wfile.close()
  File "/usr/lib/python2.7/socket.py", line 279, in close
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

我搜索了错误,发现它是一个浏览器问题。

1 个答案:

答案 0 :(得分:0)

哦,我的!这一切都是由于网址冲突造成的!

(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),

发生冲突
url(r'^(?P<country_slug>[\w-]+)/', include('Locations.urls'), name= 'country'),