Great, it works, thanks
I thought it was .error so I tried f.username.note but got an error
showed no keyword named error

Really thanks.

On Jan 30, 2:30 pm, Justin Davis <[email protected]> wrote:
> Not sure of mako syntax, but any input that failed validation will
> have a .note attribute set to the error message.  Otherwise it will be
> none.
>
> In web.py templates, it would look something like this:
>
> <tr>
>     <th>Input label</th>
>     <td>$f.email.render()
>     $if f.email.note:
>         <span class="error">$f.email.note</span>
>     </td>
> </tr>
>
> I'm guessing that transfers fairly easily over to mako syntax.
>
> -Justin
>
> On Jan 30, 12:25 am, David Shieh <[email protected]> wrote:
>
>
>
> > Hi all,
>
> > I used mako for template engine in my app, and I faced a problem of
> > form error rendering. I used individual field rendering, and it can't
> > show any form error message. Here's my handler codes:
>
> >     def POST(self, slug):
> >         f = commentForm()
> >         d['entry'], d['p'] = self.getEntry(slug)
> >         if f.validates():
> >             db.insert('comments',
> >                     createdTime=datetime.now().strftime("%Y-%m-%d %H:
> > %M"),
> >                     entryId=d['entry'].entryId, **f.d)
> >             db.update('entries',
> >                     where="id=%s" % d['entry'].entryId,
> >                     commentNum=int(d['entry'].commentNum)+1)
> >             raise web.seeother('/entry/%s/' % slug)
> >         else:
> >             d['f'] = f
> >             d['usedTime'] = time.time() - d['startTime']
> >             return render.entry(**d)
>
> > and here's the template codes:
>
> >             <form action="/entry/${ entry.entry_slug }/"
> > method="POST">
> >                 <table>
> >                     <tr>
> >                         <th>昵称(*)</th>
> >                         <td>${ f.username.render() }</td>
> >                     </tr>
> >                     <tr>
> >                         <th>Email地址(*)</th>
> >                         <td>${ f.email.render() }</td>
> >                     </tr>
> >                     <tr>
> >                         <th>个人网站</th>
> >                         <td>${ f.url.render() }</td>
> >                     </tr>
> >                     <tr>
> >                         <th>留言内容(*)</th>
> >                         <td>${ f.comment.render() }</td>
> >                     </tr>
> >                     <tr>
> >                         <th>&nbsp;</th>
> >                         <td><input type="submit" value="发表留言"
> > style="width:auto;" /></td>
> >                     </tr>
> >                 </table>
> >             </form>
>
> > when I submited an empty form or made some field error, it can't show
> > any error message. so wired. When I changed f.xxx.render() to f.render
> > () in template, it can show error message, I don't know why.
> > Any ideas?

-- 
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