It will include regular expressions. Something I'm not so good, I wrote an example, but you (or someone else here) will (I guarantee) have a more efficient way to do this. But this is just an example:
from django.template import Library, Node, TemplateSyntaxError from django.template import Template, Context register = Library() class TemplateEvalNode(Node): def __init__(self, value): self.value = Variable(value) def render(self, context): value = self.value.resolve(context) regex = re.compile('{% \w+ %}')
I have not tested this yet, so it may not work right away, but theoretically you could run:
{% template_eval object.textfield %}
And he will return:
a text with a VALUE_OF_TEMPLATETAG.
Expect updates, as I'm going to test it now and try to fix any problems, my battery is about to die, so I'm sending it now unverified.
Also expect a much smarter solution from someone who is better in Python than me: p.
EDIT: Alright, I was too slow, you beat me!
user116170
source share