, ( , , ). , , , , , ( Gmail "",).
, .html .txt , , , , .html .txt-. , : ? , , , , ?
. .html , , . :
>>> from django.template import loader
>>> from pprint import pprint
>>> template = 'emails/dun'
>>> ht = loader.get_template(template+'.html')
>>> pprint(ht.nodelist)
[<Text Node: '<p><strong>Mr. '>,
<Variable Node: user>,
<Text Node: '</strong>: Pay us $ '>,
<Variable Node: amt>,
<Text Node: ' before next Friday.</p>
'>]
, .html .txt:
>>> tt = loader.get_template(template+'.txt')
>>> pprint(tt.nodelist)
[<Variable Node: user>,
<Text Node: ': This is an important me'>,
<Variable Node: amt>,
<Text Node: '.
'>]
, , , , , (). , render().
UPDATE: , . , , ? , , , . :
>>> from django.template import loader, Context
>>> from pprint import pprint
>>> template = 'emails/dun'
>>> ht = loader.get_template(template+'.html')
>>> pprint(ht.nodelist)
[<ExtendsNode: extends "emails/base.html">]
>>> tt = loader.get_template(template+'.txt')
>>> pprint(tt.nodelist)
[<ExtendsNode: extends "emails/base.txt">]
:
>>> c = Context({'user': 'Joe', 'amt': '50.00'})
>>> tt.render(c)
u'\nJoe: This is an important message. You owe us $ 50.00.\n\n'
>>> ht.render(c)
u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xm
lns="http://www.w3.org/1999/xhtml">\n<head>\n<title></title>\n</head>\n<body>\n\n<p><strong>Mr. Joe</strong>: Pay us $ 5
0.00 before next Friday.</p>\n\n</body>\n</html>\n'
, , :
>>> template = 'emails/base'
>>> ht = loader.get_template(template+'.html')
>>> pprint(ht.nodelist)
[<Text Node: '<!DOCTYPE html PUBLIC "-/'>,
<Block Node: title. Contents: []>,
<Text Node: '</title>
</head>
<body>
'>,
<Block Node: content. Contents: []>,
<Text Node: '
</body>
</html>
'>]
>>> tt = loader.get_template(template+'.txt')
>>> pprint(tt.nodelist)
[<Block Node: content. Contents: []>, <Text Node: '
'>]
>>>