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