On Sat, Dec 4, 2010 at 3:38 PM, Maxim <[email protected]> wrote:
> Hi,
>
> I'm trying to write a custom tag that does a very simple action: sets
> the value into a variable. E.g.
> {% set variable %}The value{% endset %}
>
> Here's the essential part of the code (omitting some details):
>
> def set_tag(parser, token):
>  nodelist = parser.parse(("endset",))
>  parser.delete_first_token()
>  return SetValueNode(arg, nodelist)
>
> class SetValueNode(template.Node):
>  def __init__(self, variable, nodelist):
>    self.variable = variable
>    self.nodelist = nodelist
>
>  def render(self, context):
>    context[self.variable] = self.nodelist.render(context)
>    return ""
>
> Everything works great while I'm using ASCII symbols in a template
> (between set and endset tokens). But once I add UTF-8 symbol I get
>
> Caught an exception while rendering: ('charmap', u'\u041e
> \u0442\u0432\u0435\u0442\u044b: ', 0, 6, 'character maps to
> <undefined>')
>
> In a trace dump I noticed that this is UnicodeEncodeError, occurring
> in "self.nodelist.render(context)".
>
> Any ideas how to deal with it?

The Unicode documentation has specific information
about custom template elements:

http://docs.djangoproject.com/en/1.2/ref/unicode/#templates

-- 
Ramiro Morales

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en.

Reply via email to