Django项目关闭debug后报utf encode 和decode错误

buglife 发布于 2014/10/16 10:14
阅读 491
收藏 0

在settings.py中设置DEBUG=False TEMPLATE_DEBUG=False 并在urls.py中设置了静态资源路径   为什么打开网页的时候报500内部错误,并且在后台看到以下错误信息:

Traceback (most recent call last):
  File "/usr/lib64/python2.6/wsgiref/handlers.py", line 93, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 177, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 226, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/usr/lib/python2.6/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/views/defaults.py", line 32, in server_error
    t = loader.get_template(template_name) # You need to create a 500.html template.
  File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 145, in get_template
    template, origin = find_template(template_name)
  File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 134, in find_template
    source, display_name = loader(name, dirs)
  File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 42, in __call__
    return self.load_template(template_name, template_dirs)
  File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 45, in load_template
    source, display_name = self.load_template_source(template_name, template_dirs)
  File "/usr/lib/python2.6/site-packages/django/template/loaders/filesystem.py", line 39, in load_template_source
    return (file.read().decode(settings.FILE_CHARSET), filepath)
  File "/usr/lib64/python2.6/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc1 in position 45: invalid start byte



加载中
0
buglife
buglife
答案已找到,由于两个HTML文件的编码格式不是utf-8,而是ANSI
0
DavidWTF
DavidWTF
模版中的中文编码有问题吧。
DavidWTF
DavidWTF
同python 源文件中用中文一样。用文本编辑器把源文件改成utf8编码的,在文件最开始处加上# coding=utf-8或 # -*- coding: utf-8 -*-
buglife
buglife
应该如何处理,模版里确实有中文
返回顶部
顶部