This logic should not be handled in the template.  You should do any parsing you need in Python classes and pass the parsed value to the template.