1

I have Jinja2 2.7.3 installed and trying to render a list of files with their filesize.

When I use just the parameter vale I get:

#using {{fs}}

22528
23786
9769

If I apply the filesizeformatter the outputs are 0

#using {{fs|filesizeformat}}

0.0 kB
0.0 kB
0.0 kB

Any idea on what I'm doing wrong?

Template is as follow

<!DOCTYPE html>
<html lang="es">
  <head>
    <meta charset="utf-8">
    <title>FileBrowser</title>
  </head>
<body>

<form action="/admin/filemanager" method="post">
    <TABLE>
        <TR>
            <TD>File</TD>
            <TD>Size</TD>
            <TD>Size formatted</TD>
        </TR>

       {% for f in files %}
       <TR>
           <TD>{{f[0]}}</TD>
           <td>{{f[1]}}</td>
           <TD>{{f[1]|filesizeformat}}</TD>
       </TR>
       {% endfor %}
    </TABLE>

    <input name = "import" type="submit" value="Importar" />
    <input name = "delete" type="submit" value="Borrar" />

</form>

The call is made by:

class Handler(webapp2.RequestHandler):
    def render_str(self, template, **params):
        t = jinja_environment.get_template(template)
        return t.render(params)

    def render(self, template, **kw):
        self.write(self.render_str(template, **kw))

class view(Handler):
     def get(self):
        files=[['hello.txt',23221],['foo.txt',21211]]
        self.render('FileBrowser.html', files=files)
unaiherran
  • 1,014
  • 9
  • 21

2 Answers2

1

Thanks to @davidisn I was able to notice that the installed version of Jinja2 in the GAE SDK (and production) is 2.6

Jinja 2.6 had a bug in the fileformatter that was fixed in 2.7

Just installed manually the library in the lib folder of my project and everything worked as supposed.

Hope some one find this helpful

Community
  • 1
  • 1
unaiherran
  • 1,014
  • 9
  • 21
1

Jinja had a bug with filesizeformat until version 2.7. GAE uses Jinja-2.6 by default, so you'll need to upgrade to a newer version.

davidism
  • 121,510
  • 29
  • 395
  • 339