[Answer]-Accessing method of a container from Django template

1👍

This is a fundamental flaw in the way Django templates do expression evaluation. Look at the template tag {% expr -arbitrary-python-expression- %} for a workaround. E.g. {% expr x.bar(1,2,3) as snort %} gives you a new variable in the current Context named snort.

Alternatively, you could try Jinja2 templates. They are very close to Django’s, but they allow full Python.

Note: Jinja2 is not the same templating system as Django’s, and if you are using any page-embedded django app’s that depend on the templating system, this may break them. That is not true for the {% expr %} tag.

Leave a comment