Ticket #18155: template_err.py

File template_err.py, 739 bytes (added by Aryeh Leib Taurog <vim@…>, 13 years ago)

test script for template exception handling

Line 
1# test.py --------------
2import django
3from django.conf import settings
4from django.template import Context, Template
5import sys
6debug = ('debug' in sys.argv)
7settings_dict = dict(DEBUG=debug, TEMPLATE_DEBUG=debug)
8settings.configure(**settings_dict)
9class Foo:
10 def no_exception(self):
11 return "Method"
12 def exception(self):
13 raise AttributeError
14c = Context({"o": Foo()})
15templates = ("{{ o.no_exception }}", "{{ o.exception }}")
16print "Django version: %s" % django.get_version()
17print "settings: %r" % settings_dict
18try:
19 for ttext in templates:
20 t = Template(ttext)
21 print repr((ttext, t.render(c)))
22except Exception, e:
23 print "Caught exception: %r" % e
24# -------------
Back to Top