On Sun, 2007-08-19 at 00:27 -0700, cesco wrote:
> Thanks for your replies.
> 
> Just to avoid any doubt, I'm using __unicode__ instead of __str__ and
> I'm using the latest development version of django (post unicode
> merge).
> 
> > What is most important to know is (a) what is the data that it is
> > trying to render (both type and content).
> 
> It's trying to render an object of the class
> 'my_project.offers.models.Offer', which contains, among other fields,
> a "name" field (that is models.CharField, which in some cases contains
> danish characters) and a picture field (that is models.ImageField).
> 
> In the page I'm trying to render I display
> 1. a thumbnail of such image using the patch from 
> http://code.djangoproject.com/ticket/4115
> which is located in django.contrib.thumbnails.

This might be the problem. Looking at the last patch on #4115, it hasn't
been updated to handle the Unicode changes on trunk. It provides a
__str__ method (which isn't wrong), but it doesn't ensure that the
output of get_url() is UTF-8 encoded. Maybe there should be a call to
django.utils.encoding.iri_to_uri() in there or maybe more changes are
needed.

[...]
> Exception Type: UnicodeEncodeError
> Exception Value: 'ascii' codec can't encode character u'\xe6' in
> position 27: ordinal not in range(128)
> Exception Location: C:\Python25\lib\site-packages\django\utils
> \encoding.py in force_unicode, line 39
> Unicode error hint: The string that could not be encoded/decoded was:
> roanlæg
> 
> Traceback (most recent call last):
> File "C:\Python25\lib\site-packages\django\template\__init__.py" in
> render_node
>   754. result = node.render(context)
> File "C:\Python25\lib\site-packages\django\template\defaulttags.py" in
> render
>   134. nodelist.append(node.render(context))
> File "C:\Python25\lib\site-packages\django\template\defaulttags.py" in
> render
>   134. nodelist.append(node.render(context))
> File "C:\Python25\lib\site-packages\django\template\loader_tags.py" in
> render
>   96. return self.template.render(context)
> File "C:\Python25\lib\site-packages\django\template\__init__.py" in
> render
>   181. return self.nodelist.render(context)
> File "C:\Python25\lib\site-packages\django\template\__init__.py" in
> render
>   739. return ''.join([force_unicode(b) for b in bits])
> File "C:\Python25\lib\site-packages\django\utils\encoding.py" in
> force_unicode
>   39. s = unicode(str(s), encoding, errors)

This is interesting (the last line). It means that whatever "s" is here,
it doesn't have a __unicode__ method. Again, this isn't necessarily bad,
but it's not clear that it should be raising an encoding exception.

So, have a look at the debug screen and click on the "local variables"
link just below this last line in the extended traceback. What is "s"
here (in particular, it would be good know what type(s) is)? Also, what
is the value of 'encoding'?

If 's' doesn't look very interesting (i.e. it claims to be a string or
something like that), what is the current value of 'b' (and it's type)
in the previous line of the traceback? Again, using the "locals" link on
the debug page should be able to tell you this.

If you can't see the type of s, print it out to a file by changing that
line to something like:

        try:
            s = unicode(str(s), encoding, errors)
        except:
            # print type(s) and repr(s) to a file
            raise

I'm not completely sure why the "ascii" encoding comes into play here
unless there is no explicit __str__ method on whatever 's' is. So this
should help us get the necessary information to go a bit further.

Find out that information and report back; we should be able to work
this out.

Regards,
Malcolm

-- 
If Barbie is so popular, why do you have to buy her friends? 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to