管理中的DjangoUnicodeDecodeError与DEBUG = False

时间:2012-07-02 08:05:00

标签: django debugging administration

我对Django管理有一点奇怪的问题。在settings.py中使用DEBUG = True,一切正常。但是当我将其更改为DEBUG = False时,我无法进行项目的页面编辑。我收到这个错误:

Traceback (most recent call last):

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py, line 136, in get_response
    response = response.render()

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/response.py, line 104, in render
    self._set_content(self.rendered_content)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/response.py, line 81, in rendered_content
    content = template.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 140, in render
    return self._render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 134, in _render
    return self.nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py, line 123, in render
    return compiled_parent._render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 134, in _render
    return self.nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py, line 123, in render
    return compiled_parent._render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 134, in _render
    return self.nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py, line 62, in render
    result = block.nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py, line 62, in render
    result = block.nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py, line 192, in render
    nodelist.append(node.render(context))

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py, line 155, in render
    return self.render_template(self.template, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/loader_tags.py, line 137, in render_template
    output = template.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 140, in render
    return self._render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 134, in _render
    return self.nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py, line 192, in render
    nodelist.append(node.render(context))

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py, line 192, in render
    nodelist.append(node.render(context))

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py, line 281, in render
    return nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/defaulttags.py, line 281, in render
    return nodelist.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 823, in render
    bit = self.render_node(node, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 837, in render_node
    return node.render(context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 880, in render
    return _render_value_in_context(output, context)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/template/base.py, line 858, in _render_value_in_context
    value = force_unicode(value)

  File /home/yetty/projects/Tchorici/venv/local/lib/python2.7/site-packages/django/utils/encoding.py, line 93, in force_unicode
    raise DjangoUnicodeDecodeError(s, *e.args)

DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128). You passed in <django.forms.forms.BoundField object at 0x327bd90> (<class 'django.forms.forms.BoundField'>)

我不知道,为什么我只用DEBUG = False得到它。

2 个答案:

答案 0 :(得分:5)

我拥有它;)

在admin.py中,我有自己的MultipleChoiceField表单:

people = forms.ModelMultipleChoiceField(
    Person.objects.all(),
    widget=FilteredSelectMultiple("Účastníci", False, attrs={'rows': '10'})
)

class Meta:
    model = Event

即使我有

# -*- coding: utf-8 -*-

在文件的开头,“Účastníci”犯了麻烦。当我把它变成“Ucastnici”时,一切正常。

答案 1 :(得分:-1)

我通过实验发现错误是debug_toolbar。禁用DEBUG=True debug_toolbar