Tuesday, January 29, 2013

Re: Unicode/Non-ASCII characters in the admin throws exception

Sort of solved this issue myself; my solution was using Django 1.5c and Python 3.3. 

Allthough this means some of the reusable apps I was planning on using isn't ready for Python 3 I'll look into forking them and try to see if I can get them running myself. And if so send a patch to the maintainers. First up; Django debug toolbar :-)

Thomas


On Monday, January 28, 2013 10:07:22 PM UTC+1, Thomas Weholt wrote:
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 unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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