2012-07-02 63 views
3

Django管理我有一個奇怪的問題。在settings.py中DEBUG = True,一切正常。但是,當我將其更改爲DEBUG = False時,我無法進入頁面編輯項目。我得到這個錯誤:DjangoUnicodeDecodeError在管理與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 =假。

回答

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」時,一切正常。

+0

我會說編碼網頁是一回事,另一件事是數據庫編碼。檢查數據庫的排序規則和字符集 – matcheek

+2

您使用的是Django,這意味着您在3.0之前仍然使用Python版本,這意味着您需要[標記Unicode字符串](http://docs.python.org/howto /unicode.html#the-unicode-type)。使用'u「Účastníci」'而不是'「Účastníci」'它應該可以工作。 – roam

+0

我檢查了排序規則 - 多數民衆贊成在所有權利。 Unicode標記不起作用。我重複 - 一切只與DEBUG = False,與DEBUG = True它工作正常。 – yetty

-1

我通過實驗發現錯誤是debug_toolbar。與DEBUG=True debug_toolbar已禁用

相關問題