1
# -*- coding: utf-8 -*-
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
12
>>> s = '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91 {{ var }}'
14
>>> s = '\x80\xc5\xc0'
16
Traceback (most recent call last):
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)
33
>>> isinstance(t1.render(c3), unicode)
35
>>> isinstance(t1.render(c3), SafeData)