Debian Codegraph @

examples/demo_scripts/django_template_render.py

raw symbols SCIP
1 import os
2 from optparse import OptionParser
3
4 try:
5 import django
6 except ImportError:
7 print("This example requires Django.")
8 print("Install using `pip install Django`.")
9 exit(1)
10
11 import django.conf
12 import django.template.loader
13
14
15 def main():
16 parser = OptionParser()
17 parser.add_option(
18 "-i",
19 "--iterations",
20 dest="iterations",
21 action="store",
22 type="int",
23 help="number of template render calls to make",
24 default=200,
25 )
26 options, _ = parser.parse_args()
27
28 os.chdir(os.path.dirname(__file__))
29
30 django.conf.settings.configure(
31 INSTALLED_APPS=(),
32 TEMPLATES=[
33 {
34 "BACKEND": "django.template.backends.django.DjangoTemplates",
35 "DIRS": ["./django_example/django_example/templates"],
36 }
37 ],
38 )
39 django.setup()
40
41 render_templates(options.iterations)
42
43
44 def render_templates(iterations: int):
45 for _ in range(0, iterations):
46 django.template.loader.render_to_string("template.html")
47
48
49 if __name__ == "__main__":
50 main()