Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#6235 closed (invalid)

Unicode error when report template error.

Reported by: flytwokites <towjzhou@…> Owned by: nobody
Component: Template system Version: dev
Severity: Keywords: unicode, template
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a template error occurred, and a non english char in this template(i.e. Chinese chars), The error report page is not report the template error, instead of a unicode error. I found it can be fixed in django\template\context.py(line:18):

    def __repr__(self):
        try:
            return repr(self.dicts) #This line cause unicode error when shows non english char.!!!
        except:
            return 'Ohhh: Context text...'

Change History (3)

in reply to:  description comment:1 by Thejaswi Puthraya, 17 years ago

Keywords: template added

Replying to flytwokites <towjzhou@hotmail.com>:

When a template error occurred, and a non english char in this template(i.e. Chinese chars), The error report page is not report the template error, instead of a unicode error. I found it can be fixed in django\template\context.py(line:18):

It would help if you give specific information. I have tried two cases and I am unable to replicate your error:

Case-1

>>> t=template.Template("{% if a %}अथवा{% endif %}")
>>> t.render(template.context({"a": 1},autoescape=True))
u'\u0905\u0925\u0935\u093e'

If you are getting an error in this case, I can't reproduce it.

Case-2

>>> t=template.Template("{% if अथवा %}Yes{% endif %}")

If that is what you are looking at, i don't think it is possible to do it in the templating language.

comment:2 by Thomas Güttler, 17 years ago

Resolution: invalid
Status: newclosed

Ticket reporter was asked for more information. No feedback since two months. Closing it. Please reopen if more information (reproduceable traceback)
is given.

comment:3 by jefurii, 17 years ago

I can confirm what thejaswi_puthraya wrote:

This template code (Unicode text in template body, but no endif tag)...

{% if django %}
世界中のコミュニティ

...results in the following:

TemplateSyntaxError at /django/
Unclosed tag 'if'. Looking for one of: else, endif 

As described in Case-2, adding Unicode text inside a tag...

{% if 世界中のコミュニティ %}it works{% endif %}

...results in a UnicodeEncodeError.

UnicodeEncodeError at /django/
'ascii' codec can't encode characters in position 0-9: ordinal not in range(128)

It could be that flytwokites was inserted text in one of the non-Unicode Chinese encodings (GB18030, Big5) in templates. That's not Unicode, so wouldn't be something we'd support anyway.

Note: See TracTickets for help on using tickets.
Back to Top