Monday, January 28, 2013

Unicode/Non-ASCII characters in the admin throws exception

This is a recurring problem for django users obviously by the amount of posts returned by google and I've had this problem in the past as well, but cannot remember how I got around it. Googling did'nt help either.

When I use Norweian characters like ØÆÅ in CharField-field in the django admin I get an exception when I click the add-button to register the new entry.

Traceback:

File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response

  136.                     response = response.render()

File "C:\Python27\lib\site-packages\django\template\response.py" in render

  104.             self._set_content(self.rendered_content)

File "C:\Python27\lib\site-packages\django\template\response.py" in rendered_content

  81.         content = template.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  140.             return self._render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in _render

  134.         return self.nodelist.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  823.                 bit = self.render_node(node, context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node

  74.             return node.render(context)

File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in render

  123.         return compiled_parent._render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in _render

  134.         return self.nodelist.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  823.                 bit = self.render_node(node, context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node

  74.             return node.render(context)

File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in render

  123.         return compiled_parent._render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in _render

  134.         return self.nodelist.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  823.                 bit = self.render_node(node, context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node

  74.             return node.render(context)

File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in render

  123.         return compiled_parent._render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in _render

  134.         return self.nodelist.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  823.                 bit = self.render_node(node, context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node

  74.             return node.render(context)

File "C:\Python27\lib\site-packages\django\template\defaulttags.py" in render

  281.                 return nodelist.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  823.                 bit = self.render_node(node, context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node

  74.             return node.render(context)

File "C:\Python27\lib\site-packages\django\template\loader_tags.py" in render

  62.             result = block.nodelist.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  823.                 bit = self.render_node(node, context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node

  74.             return node.render(context)

File "C:\Python27\lib\site-packages\django\template\defaulttags.py" in render

  281.                 return nodelist.render(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in render

  823.                 bit = self.render_node(node, context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render_node

  74.             return node.render(context)

File "C:\Python27\lib\site-packages\django\template\debug.py" in render

  84.             output = self.filter_expression.resolve(context)

File "C:\Python27\lib\site-packages\django\template\base.py" in resolve

  599.                 new_obj = func(obj, *arg_vals)

File "C:\Python27\lib\site-packages\django\template\defaultfilters.py" in _dec

  39.             args[0] = force_unicode(args[0])

File "C:\Python27\lib\site-packages\django\utils\encoding.py" in force_unicode

  74.                     s = unicode(str(s), encoding, errors)


Exception Type: UnicodeEncodeError at /admin/storyquest/story/11/

Exception Value: 'ascii' codec can't encode character u'\xd8' in position 0: ordinal not in range(128)


I'm running Python 2.7.3, django 1.4.3 on Windows 8 64bit. The model in question:

class Story(models.Model):
    title = models.CharField(max_length=200)


Regards,
Thomas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment