开发者

DjangoUnicodeDecodeError on static image

I am getting this error when trying to include a static image in Django.

Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/django/core/servers/basehttp.py", line 280, in run
self.result = application(self.environ, self.start_response)
File "/Library/Python/2.6/site-packages/django/core/servers/basehttp.py", line 674, in __call__
return self.application(environ, start_response)
File "/Library/Python/2.6/site-packages/django/core/handlers/wsgi.py", line 245, in __call__
response = middleware_method(request, response)
File "/Users/Josh/djcode/lists/debug_toolbar/middleware.py", line 105, in process_response
smart_unicode(response.content),
File "/Library/Python/2.6/site-packages/django/utils/encoding.py", line 39, in smart_unicode
return force_unicode(s, encoding, strings_only, errors)
File "/Library/Python/2.6/site-packages/django/utils/encoding.py", line 88, in force_unicode
raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0x89 in position 0: unexpected code byte. You passed in '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00P\x00\x00\x00H\x08\x06\x00\x00\x00a\x94r[\x00\x00\x00\tpHYs\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a\x9c\x18\x00\x00\nOiCCPPhotoshop ICC profile\x00\x00x\xda\x9dSgTS\xe9\x16=\xf7\xde\xf4BK\x88\x80\x94KoR....`\x82' (<type 'str'>)

I am using this to serve my static media:

if settings.DEBUG:
  urlpatterns += patterns('',
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
  )

and here is my settings.py (having tried the STATIC_ROOT with and without the trailing slash:

STATIC_URL = '/medi开发者_开发问答a/'
STATIC_ROOT = '/Users/Josh/djcode/static_media'

CSS and javascript files work fine, however images do not. Here is my HTML: <img src="/media/img/new_list_button.png" alt="Make a new list."/>

Thanks in advance for any help.


What's in your TEMPLATE_CONTEXT_PROCESSORS? Dont you forget to add django.core.context_processors.static?

http://docs.djangoproject.com/en/dev/howto/static-files/#with-a-context-processor

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜