{% 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 3 years, 3 months ago
  2. Using the built-in slugify filter outside a template by jcroft 6 years, 3 months ago
  3. create_update for newforms (ModelForm) by Rozza 5 years, 3 months ago
  4. create_object and update_object for newforms by danjak 6 years, 3 months ago
  5. Quiet runserver by danielroseman 3 years 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?)