It doesn't even work if you declare the class method as a template
global like this:

    from datetime import datetime
    tg = {'strftime': datetime.strftime}
    render = web.template.render('templates/', globals=tg)

    $strftime(date, '%m %Y')

Why?

A workaround is to declare a proxy function like this:

    from datetime import datetime
    def strftime(date, format):
        return datetime.strftime(date, format)
    tg = {'strftime': strftime}
    render = web.template.render('templates/', globals=tg)

    $strftime(date, '%m %Y')    => 04 2009

JP


On 2 abr, 09:20, Fabien Grumelard <[email protected]> wrote:
> Hello,
>
> I would like to format a date variable in a template. If I have a
> "date" variable (which contains datetime.date.today()), I get this
> error when I write "$date.strftime('%m %Y')" in the template:
>
>  <type 'exceptions.KeyError'> at /
>
>    '__import__'
>
> Python     templates/index.html in __template__, line 6
> Web     GEThttp://localhost:8080/
>
>    Traceback (innermost first)
>
>    * |templates/index.html| in |__template__|
>         0. $def with (user, rediffuseur, contrats, date)
>         1. $var title: Page d'accueil
>         2. <div id="menu"><a href="/">Accueil</a> <a
>            href="/logout">Déconnexion</a></div>
>         3. <div id="content">
>         4. Société : $rediffuseur.nom<br>
>         5. Utilisateur : $user.prenom $user.nom<br>
>         6. $date.strftime("%m %Y")
>
> If I just put "$date", that works but that not what I want. Is it a
> bug ? The workaround is to put $date.strftime("%m %Y") into $date from
> the python code but it's not very pretty.
>
> Thanks,
> Fabien Grumelard
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to