I just ran into an issue where i was getting unicode errors when trying 
to insert data into mysql (via a model).

I had this code:

--
from django.contrib.markup.templatetags.markup import markdown

def save(self):
        self.content_html = markdown(self.content_source)
                
        super(Chapter, self).save()
--

self.content_source is utf-8

This would cause a unicode error when the code tried to save the string 
in the DB (mysql) if content_source contained any non-ascii chars.

I was able to fix this by explicitly setting the encoding on the string 
returned from markdown()

--
from django.contrib.markup.templatetags.markup import markdown

def save(self):
        self.content_html = markdown(self.content_source).encode("utf-8")
                
        super(Chapter, self).save()
--

However, I would have expected the markdown function to return the 
correctly encoded string.

Here is a simple script that I believe shows the difference in output:

--
from django.contrib.markup.templatetags.markup import markdown

tmp = u'Andr\202'
m = markdown(tmp)
print m
m = markdown(tmp).encode("utf-8")
print m
--

Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
django.VERSION (0, 97, 'pre')

I am pretty new to django, and dont have much experience working with 
unicode, so I wanted to post here to see if anyone thought that this 
looked like a bug? If so I will log it.

mike


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to