Django

Code

Ticket #2996 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

[possible patch] template.Nodelist.render and non-ascii data

Reported by: Max Derkachev <mderk@yandex.ru> Assigned to: adrian
Milestone: Component: Template system
Version: SVN Keywords: unicode-branch
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

template.Nodelist.render raised an exception in

return ''.join(bits)

UnicodeDecodeError? : 'ascii' codec can't decode byte 0xd1 in position 3128: ordinal not in range(128)

The problem was that the content it tried to join had UTF-8 characters. The *temporary* patch that worked for me was to write the render method as follows:

def render(self, context):
    bits = []
    for node in self:
        if isinstance(node, Node):
            bits.append(self.render_node(node, context).decode(settings.DEFAULT_CHARSET))
        else:
            bits.append(node.decode(settings.DEFAULT_CHARSET))
    return ''.join(bits).encode(settings.DEFAULT_CHARSET)

However, I suppose the bug can be deeper than this and should be fixed somewhere else.

regards, Max

Attachments

Change History

05/14/07 17:09:03 changed by mtredinnick

  • keywords set to unicode-branch.

This was fixed in the unicode-branch, in [4971]. I will close the ticket once the branch is merged into trunk.

06/20/07 23:16:46 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

07/04/07 07:11:05 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [5609]) Merged Unicode branch into trunk (r4952:5608). This should be fully backwards compatible for all practical purposes.

Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702


Add/Change #2996 ([possible patch] template.Nodelist.render and non-ascii data)




Change Properties
Action