質問

When I starts Python 2.7+Django app and try to go http://127.0.0.1:8000/admin/ I see only text without normal display. It happens only winth Python 2.7. When I use Python 3.3 everything is OK. But I need exactly Python 2.7. Here is my errors

[19/Mar/2014 12:39:00] "GET /admin/ HTTP/1.1" 200 2990
Traceback (most recent call last):
  File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 68, in __call__
    return super(StaticFilesHandler, self).__call__(environ, start_response)
  File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 206, in __call__
    response = self.get_response(request)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 58, in get_response
    return self.serve(request)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 51, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\views.py", line 41, in serve
    return static.serve(request, path, document_root=document_root, **kwargs)
  File "C:\Python27\lib\site-packages\django\views\static.py", line 61, in serve
    content_type, encoding = mimetypes.guess_type(fullpath)
  File "C:\Python27\lib\mimetypes.py", line 297, in guess_type
    init()
  File "C:\Python27\lib\mimetypes.py", line 358, in init
    db.read_windows_registry()
  File "C:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "C:\Python27\lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd8 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 68, in __call__
    return super(StaticFilesHandler, self).__call__(environ, start_response)
  File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 206, in __call__
    response = self.get_response(request)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 58, in get_response
    return self.serve(request)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 51, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\views.py", line 41, in serve
    return static.serve(request, path, document_root=document_root, **kwargs)
  File "C:\Python27\lib\site-packages\django\views\static.py", line 61, in serve
    content_type, encoding = mimetypes.guess_type(fullpath)
  File "C:\Python27\lib\mimetypes.py", line 297, in guess_type
    init()
  File "C:\Python27\lib\mimetypes.py", line 358, in init
    db.read_windows_registry()
  File "C:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "C:\Python27\lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd8 in position 0: ordinal not in range(128)

Help me please!

役に立ちましたか?

解決 2

I find answer! It needed create file sitecustomize.py C:\Python27\Lib\site-packages. And write there:

import sys

sys.setdefaultencoding("cp1251")

And all works)

他のヒント

you can use vim or other text editor which can tell the 16bit coding check the view and the template file again.I

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top