Skip to content

Commit 212a218

Browse files
committed
add profiling templatetag
1 parent dbb1790 commit 212a218

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

template_profiler_panel/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django import template
2+
from django.template.base import Node
3+
4+
5+
register = template.Library()
6+
7+
8+
@register.tag
9+
def profile(parser, tags):
10+
nodelist = parser.parse(('endprofile',))
11+
parser.delete_first_token()
12+
return ProfileNode(nodelist, tags)
13+
14+
15+
class ProfileNode(Node):
16+
def __init__(self, nodelist, tags):
17+
self.nodelist = nodelist
18+
self.block_name = tags.contents.split(' ')[1].strip("'")
19+
20+
def __str__(self):
21+
return f"Profile {self.block_name}"
22+
23+
def render(self, context):
24+
result = self.nodelist.render(context)
25+
return result

0 commit comments

Comments
 (0)