{% eval %} templatetag-evaluate expressions

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from django import template

register = template.Library()

@register.tag(name='eval')
def do_eval(parser, token):
    "Usage: {% eval %}1 + 1{% endeval %}"

    nodelist = parser.parse(('endeval',))

    class EvalNode(template.Node):
        def render(self, context):
            return eval(nodelist.render(context))
 
    parser.delete_first_token()
    return EvalNode()

More like this

  1. FloatField with safe expression parsing by joelegner 1 year, 11 months ago
  2. math tag by itchyfingrs 9 months, 1 week ago
  3. A templatetag to insert the output of another view (or local URL) by jamesgpearce 2 years, 7 months ago
  4. Automatic Paragraphs by Mirrorball 4 years, 6 months ago
  5. Template tag "ifregex" and "ifnotregex" by arthurfurlan 2 years, 8 months ago

Comments

Cross20ALLISON (on December 30, 2011):

Some specialists argue that personal loans aid people to live the way they want, because they are able to feel free to buy needed stuff. Moreover, some banks present auto loan for young and old people.

#

(Forgotten your password?)