Another gotcha:
I had some code that would render a page using template.render, and then stuff
it into a string attribute of a Model. Render used to emit utf-8 encoded 7-bit
text, so my code read:
content = template.render(…stuff…)
...
r.content = content.decode("utf-8")
which turned it into a unicode string that I could store. This started
throwing exceptions like this:
File "/base/data/home/apps/towngovernment/40.351480691801932340/main.py",
line 889, in makeReceipt
r.content = content.decode("utf-8")
File "/base/python_runtime/python_dist/lib/python2.5/encodings/utf_8.py",
line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in position
259: ordinal not in range(128)
I'm guessing that django 1.2 now returns a unicode string and expects someone
else to turn it into utf-8. So I changed this to just:
r.content = content
And it's working correctly now.
-Joshua
On Jun 28, 2011, at 4:27 PM, Joshua Smith wrote:
> The pricing FAQ says that to take advantage of threading in python that we'll
> need to update our code to Django 1.2.
>
> In anticipation of that, I've added these lines at the very top of several
> apps' main.py files:
>
> from google.appengine.dist import use_library
> use_library('django', '1.2')
>
> I only use django for template substitution, so my reading of various porting
> FAQs lead me to anticipate that my only problem would be that I need to add
> "|safe" in a few places where I have markup in an attribute.
>
> But it turns out my code hit one other surprise. The return value of
> defaultfilters.slugify now doesn't return a plain string, but rather a
> django.utils.safestring.SafeUnicode. You can't pass that into something that
> is expecting a string. For example:
>
> SomeModel.gql("WHERE slug = :1", defaultfilters.slugify(name))
>
> will throw an exception. The fix is simple: wrap that call with a str():
>
> SomeModel.gql("WHERE slug = :1", str(defaultfilters.slugify(name)))
>
> Hope this info helps someone else avoid an exception!
>
> -Joshua
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.