Ah - ok, I see! My knowledge of the unicode area is lacking, so I
hadn't actually realized we were overriding a built-in by defining
__unicode__. Completely obvious now that you point it out of course.
I don't need to be returning a string instead of unicode. I just
inadvertantly ended up doing that due to the fact that my widget, in
certain cases, does not need to provide an input and thus was not
calling its super() method. I'm used to using strings rather than
unicode, so the resulting widget was just rendering some html for
display only, and my render() method was returning it as a string
rather than as unicode. In all other cases where I've done this sort
of thing, I think I at some point ended up concatenating my html onto
the return value of the widget's super() method, or concatenating it
with the return of render_to_string(), and both of those have the
effect of turning it into unicode, so I just never noticed the
problem.
So possibly a silly question, but is it considered best practice to
code all strings as unicode as you write them, or is it better to
convert to unicode at the end? IE
def render(self, name, value, attrs=None):
rendered = u'<div> blah blah blah </div>'
rendered += u'<div> blah blah blah </div>'
return mark-safe(rendered)
vs:
def render(self, name, value, attrs=None):
rendered = '<div> blah blah blah </div>'
rendered += '<div> blah blah blah </div>'
return mark_safe(unicode(rendered))
Or maybe it doesn't matter at all, just curious if there is some
benefit to one versus the other.
I do recognize that what I'm doing above is ugly and that the html
should go into the template, and eventually I will move it there.
Sometimes it's just easier to live in python when debugging and not
have the added complexity of the template.
Ok, thanks for your response, that clarified a lot.
Margie
On Oct 14, 10:21 pm, Karen Tracey <
kmtra...@gmail.com> wrote:
> On Wed, Oct 14, 2009 at 6:25 PM, Margie Roginski
> <
margierogin...@yahoo.com>wrote: