webhelpers

0 views
Skip to first unread message

Antipin Aleksei

unread,
Apr 17, 2007, 7:05:11 AM4/17/07
to pylons-discuss
Hi

I configured Pylons to be used with Mako. It works greate, but I can't
make webhelpers work.
In an inhereted template I had simple login form- it was rendered as I
expected. Then I tried to switch to using webhelpers to generate the
same form. But it doesn't work for me.
I added to helpers.py
from webhelpers.rails import *

But then I tried the following in my template:

+
<% h.text_field('email') %>
<% h.url_for('index2') %>
<% h.url_for(controller='index', action='login') %>
+

I get only "++", no errors.

What should I do to get this code working. And can anyone tell is
there any advantages of using webhelper for generating html instead of
simple html code.

I am using
pylons-0.9.6dev_r1956-py2.5.egg
mako-0.1.5-py2.5.egg
webhelpers-0.3-py2.5.egg

Thanks for your help.

Christoph Haas

unread,
Apr 17, 2007, 7:12:39 AM4/17/07
to pylons-...@googlegroups.com
On Tue, Apr 17, 2007 at 04:05:11AM -0700, Antipin Aleksei wrote:
> I configured Pylons to be used with Mako. It works greate, but I can't
> make webhelpers work.
> In an inhereted template I had simple login form- it was rendered as I
> expected. Then I tried to switch to using webhelpers to generate the
> same form. But it doesn't work for me.
> I added to helpers.py
> from webhelpers.rails import *
>
> But then I tried the following in my template:
>
> +
> <% h.text_field('email') %>
> <% h.url_for('index2') %>
> <% h.url_for(controller='index', action='login') %>
> +

Try ${ h.foobar() } instead of <% h.foobar() %>

Although <% ... %> should allow Python statements it doesn't output them
directly. A <% print h.text_field(...) %> may have worked but ${} is
preferred.

Christoph

Antipin Aleksei

unread,
Apr 17, 2007, 7:18:52 AM4/17/07
to pylons-...@googlegroups.com

> Try ${ h.foobar() } instead of <% h.foobar() %>
>
> Although <% ... %> should allow Python statements it doesn't output them
> directly. A <% print h.text_field(...) %> may have worked but ${} is
> preferred.
>
> Christoph
>
It works. But strange- when I was playing with template inheritance I
found that <% a = $self.foobar()%> prints to output at once. Maybe it
differs for self/parent/next objects.

Thank you.

--
Best regards,
Antipin Aleksei

Shannon -jj Behrens

unread,
Apr 17, 2007, 8:49:16 PM4/17/07
to pylons-...@googlegroups.com
> And can anyone tell is
> there any advantages of using webhelper for generating html instead of
> simple html code.

I'm using Genshi instead of Mako, but if I were using Mako, I would
use Web helpers because a) they're convenient b) they're a great way
to ensure that data gets properly escaped.

Best Regards,
-jj

--
"'Software Engineering' is something of an oxymoron. It's very
difficult to have real engineering before you have physics, and there
isn't anything even close to a physics for software." -- L. Peter
Deutsch

Loucash

unread,
Apr 19, 2007, 11:49:32 AM4/19/07
to pylons-discuss
Hi.
In config/middleware.py set something like this:

config.init_app(global_conf, app_conf, package='your_project_name')
makopts = {}
config.add_template_engine('mako', 'your_project_name.templates',
makopts)

It works for me.
Regards.
Łukasz Biedrycki

Antipin Aleksei

unread,
Apr 22, 2007, 5:43:50 AM4/22/07
to pylons-...@googlegroups.com
I tried it and I get error on <%inherit file="base.html"/> saying there
must be <%inherit file="base.html"/%>.
After that error reported bad name definition "header()" in <%def
name="header()">.

With simple
config.init_app(global_conf, app_conf, package='pyoner',
template_engine='mako')
in middleware.py I have never got those errors and everything works just
fine, except for the topic;-).

Mike Orr

unread,
Apr 25, 2007, 11:13:22 AM4/25/07
to pylons-...@googlegroups.com
On 4/22/07, Antipin Aleksei <antipin...@gmail.com> wrote:
>
>
> > Hi.
> > In config/middleware.py set something like this:
> >
> > config.init_app(global_conf, app_conf, package='your_project_name')
> > makopts = {}
> > config.add_template_engine('mako', 'your_project_name.templates',
> > makopts)
> >
> > It works for me.
> > Regards.
> > Łukasz Biedrycki
> >
> I tried it and I get error on <%inherit file="base.html"/> saying there
> must be <%inherit file="base.html"/%>.
> After that error reported bad name definition "header()" in <%def
> name="header()">.

Those are Myghty errors. The default engine is still Myghty. You'd
have to put "config.template_engines = []" before the add line, or use
the template_engine arg below.

> With simple
> config.init_app(global_conf, app_conf, package='pyoner',
> template_engine='mako')
> in middleware.py I have never got those errors and everything works just
> fine, except for the topic;-).

--
Mike Orr <slugg...@gmail.com>

Antipin Aleksei

unread,
Apr 25, 2007, 2:02:41 PM4/25/07
to pylons-...@googlegroups.com

> Those are Myghty errors. The default engine is still Myghty. You'd
> have to put "config.template_engines = []" before the add line, or use
> the template_engine arg below.
>

It's strange- errors are gone, but <%%> syntax dosen't work :)

Reply all
Reply to author
Forward
0 new messages