Search code examples
djangodebuggingadministration

DjangoUnicodeDecodeError in administration with DEBUG=False


I have a little wierd problem with Django administration. With DEBUG=True in settings.py, everything works fine. But when I change it to DEBUG=False, I can't get to page editation of item. I get this error:

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'>)

I have no idea, why I get it just with DEBUG=False.


Solution

  • I have it ;)

    In admin.py I have own form for MultipleChoiceField:

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

    Even if I had

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

    on the beginning of the file, "Účastníci" made troubles. When I changed it to "Ucastnici", everything works fine.