Fixed #6057 -- Mark rendered template output as safe for auto-escaping purposes.
[django.git] / tests / regressiontests / templates / unicode.py
blobe5f308d20215916e7615c457cc107fbede593769
1 # -*- coding: utf-8 -*-
3 unicode_tests = ur"""
4 Templates can be created from unicode strings.
5 >>> from django.template import *
6 >>> from django.utils.safestring import SafeData
7 >>> t1 = Template(u'ŠĐĆŽćžšđ {{ var }}')
9 Templates can also be created from bytestrings. These are assumed by encoded
10 using UTF-8.
12 >>> s = '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91 {{ var }}'
13 >>> t2 = Template(s)
14 >>> s = '\x80\xc5\xc0'
15 >>> Template(s)
16 Traceback (most recent call last):
17 ...
18 TemplateEncodingError: Templates can only be constructed from unicode or UTF-8 strings.
20 Contexts can be constructed from unicode or UTF-8 bytestrings.
22 >>> c1 = Context({'var': 'foo'})
23 >>> c2 = Context({u'var': 'foo'})
24 >>> c3 = Context({'var': u'Đđ'})
25 >>> c4 = Context({u'var': '\xc4\x90\xc4\x91'})
27 Since both templates and all four contexts represent the same thing, they all
28 render the same (and are returned as unicode objects and "safe" objects as
29 well, for auto-escaping purposes).
31 >>> t1.render(c3) == t2.render(c3)
32 True
33 >>> isinstance(t1.render(c3), unicode)
34 True
35 >>> isinstance(t1.render(c3), SafeData)
36 True
37 """