-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_template.py
More file actions
60 lines (51 loc) · 2.03 KB
/
debug_template.py
File metadata and controls
60 lines (51 loc) · 2.03 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import django
from django.conf import settings
from django.template import Template, Context, Engine
# Minimal Django setup
if not settings.configured:
settings.configure(
TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.getcwd(), 'trading', 'templates')],
'APP_DIRS': True,
}],
INSTALLED_APPS=['django.contrib.humanize'],
)
django.setup()
template_path = 'trading/templates/trading/detalhe_estrutura.html'
with open(template_path, 'r', encoding='utf-8') as f:
template_content = f.read()
try:
# Try to compile the template
Template(template_content)
print("Template compiled successfully!")
except Exception as e:
print(f"Template compilation failed: {e}")
import re
ifs = len(re.findall(r'{%\s*if', template_content))
elifs = len(re.findall(r'{%\s*elif', template_content))
elses = len(re.findall(r'{%\s*else', template_content))
endifs = len(re.findall(r'{%\s*endif', template_content))
fors = len(re.findall(r'{%\s*for', template_content))
endfors = len(re.findall(r'{%\s*endfor', template_content))
blocks = len(re.findall(r'{%\s*block', template_content))
endblocks = len(re.findall(r'{%\s*endblock', template_content))
print(f"Stats:")
print(f" IF: {ifs}, ELIF: {elifs}, ELSE: {elses}, ENDIF: {endifs}")
print(f" FOR: {fors}, ENDFOR: {endfors}")
print(f" BLOCK: {blocks}, ENDBLOCK: {endblocks}")
if ifs > endifs:
print(f"MISSING {ifs - endifs} endif tag(s)!")
elif endifs > ifs:
print(f"EXTRA {endifs - ifs} endif tag(s)!")
if fors > endfors:
print(f"MISSING {fors - endfors} endfor tag(s)!")
elif endfors > fors:
print(f"EXTRA {endfors - fors} endfor tag(s)!")
if blocks > endblocks:
print(f"MISSING {blocks - endblocks} endblock tag(s)!")
elif endblocks > blocks:
print(f"EXTRA {endblocks - blocks} endblock tag(s)!")
import traceback
traceback.print_exc()