[Django]-Is there an easy way reverse a template render?

0πŸ‘

βœ…

I found a very similar way to do it without Django templates that would have worked well for me at the time:

import re

tmpl = 'My name is (?P<name>.*).\nI like to ride my (?P<transport>.*).'
msg = 'My name is Adrian.\nI like to ride my bicycle.'
print(re.compile(tmpl).match(msg).groupdict())

Outputs:

{'name': 'Adrian', 'transport': 'bicycle'}

The XML regular expression template could still be kept in an XML file and read in at runtime.

πŸ‘€Brad Pitcher

1πŸ‘

As far as I know this is not a Django feature. So, no, there is no way in Django. If you have the template, you will have to create a way of parsing the html/xml, and compare it with the template in order to associate each change to each {{context_label}}.

This seems like an interesting problem, but I don’t see how its solution can be useful in a standard web-app (thus I see no reason why Django would have this feature in the first place).

πŸ‘€Jorge Leitao

Leave a comment