无法在Django中加载媒体文件(在Windows上)

时间:2012-02-07 05:39:21

标签: django django-views python-2.7

当我试图加载时     http://127.0.0.1:8000/media/javascripts/bg-input.png

我得到了一个500 http的回复说:

UnicodeDecodeError at /media/javascripts/bg-input.png
'ascii' codec can't decode byte 0xca in position 0: ordinal not in range(128)
Request Method: GET
Request URL:    http://127.0.0.1:8000/media/javascripts/bg-input.png
Django Version: 1.3.1
Exception Type: UnicodeDecodeError
Exception Value:    
'ascii' codec can't decode byte 0xca in position 0: ordinal not in range(128)
Exception Location: T:\Python27\lib\mimetypes.py in enum_types, line 250
Python Executable:  T:\Python27\python.exe
Python Version: 2.7.0
Python Path:    
['T:\\djangos\\deadline',
 'T:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg',
 'T:\\Python27\\lib\\site-packages\\django_pagination-1.0.7-py2.7.egg',
 'T:\\Python27\\lib\\site-packages\\simplejson-2.3.2-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'T:\\Python27\\DLLs',
 'T:\\Python27\\lib',
 'T:\\Python27\\lib\\plat-win',
 'T:\\Python27\\lib\\lib-tk',
 'T:\\Python27',
 'T:\\Python27\\lib\\site-packages',
 'T:\\Python27\\lib\\site-packages\\PIL']
Server time:    星期二, 7 二月 2012 13:33:53 +0800

Unicode错误提示 无法编码/解码的字符串是: / x

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/media/javascripts/bg-input.png

Django Version: 1.3.1
Python Version: 2.7.0
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'pagination',
 'deadline.reg',
 'deadline.helpers',
 'deadline.users',
 'deadline.tasks',
 'deadline.comments']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'pagination.middleware.PaginationMiddleware')


Traceback:
File "T:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "T:\Python27\lib\site-packages\django\views\static.py" in serve
  54.     mimetype, encoding = mimetypes.guess_type(fullpath)
File "T:\Python27\lib\mimetypes.py" in guess_type
  294.         init()
File "T:\Python27\lib\mimetypes.py" in init
  355.             db.read_windows_registry()
File "T:\Python27\lib\mimetypes.py" in read_windows_registry
  260.             for ctype in enum_types(mimedb):
File "T:\Python27\lib\mimetypes.py" in enum_types
  250.                     ctype = ctype.encode(default_encoding) # omit in 3.x!

Exception Type: UnicodeDecodeError at /media/javascripts/bg-input.png
Exception Value: 'ascii' codec can't decode byte 0xca in position 0: ordinal not in range(128)

当我在Windows上运行时会发生这种情况。在ubuntu中它运行正常。

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = 'T:/djangos/deadline/media/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

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

0 个答案:

没有答案