Merge pull request #135 from jhpyle/error-context

Added test script for TemplateError trapping
This commit is contained in:
Eric Lapouyade 2018-08-07 10:19:57 +02:00 committed by GitHub
commit cb6971009f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

15
tests/template_error.py Normal file
View File

@ -0,0 +1,15 @@
from docxtpl import DocxTemplate, RichText
from jinja2.exceptions import TemplateError
try:
tpl = DocxTemplate('test_files/template_error_tpl.docx')
tpl.render({
'test_variable' : 'test variable value'
})
except TemplateError as the_error:
print unicode(the_error)
if hasattr(the_error, 'docx_context'):
print "Context:"
for line in the_error.docx_context:
print line
tpl.save('test_files/template_error.docx')

Binary file not shown.

Binary file not shown.