You can do it in a custom eval-like tag: @register.tag() def evalpy(parser, token): try: tag_name, expression = token.split_contents() except ValueError: raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0] if not (expression[0] == expression[-1] and expression[0] in ('"', "'")): raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name return EvalNode(expression[1:-1])
class EvalNode(template.Node): def __init__(self, expression): self.expression = expression def render(self, context): return eval(self.expression, {}, context) and then use it like below. Note you can access context/template variables this way: {% get_comment_count for post as comment_count %} <h1>{% evalpy "comment_count + 3" %}</h1> Kludgy, yes, but sometimes useful. -Dave On Nov 18, 3:26 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > > I am thinking about something like {{ (width - 5) *12 }} ? > > No. That syntax is not supported in Django templates. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---