Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6235 closed (invalid)

Unicode error when report template error.

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

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...'

Attachments (0)

Change History (3)

comment:1 in reply to: ↑ description Changed 6 years ago by thejaswi_puthraya

  • Keywords unicode, template added; unicode removed
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 6 years ago by guettli

  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 6 years ago by jefurii

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.