I tried to have the jinja2 decorator inside a separate file in
controllers, with no success. My other controller simply can't find
the other files inside his package. O.O.

Oh, about the discussion, web2py template system does not seems
pythonic to me, not at all. It is not pretty(python has to be pretty),
and does not enphasys logic outsite templates, as you'll run python
code directly inside the templates. This kind of approach has proven
bad in lot's of languages and systems, from php to jsp and more.

{{text|e}} <= pretty

{{escape(text)}} <= not so much

pretty
{% for stuff in other_stuff %}
do stuff with {{stuff}}
{% endfor %}

not so much
{{ for stuff in other_stuff }}
do stuff with {{=stuff}}
{{pass}}

On 26 dez, 07:22, Massimo Di Pierro <[email protected]> wrote:
> > ERRATA: Try this instead.
>
> def jinja2(f):
>      def _jinja2():
>          d=f()
>          if isinstance(d,dict):
>              from jinja2 import Environment, FileSystemLoader
>              env = Environment(loader=FileSystemLoader(os.path.join
> (request.folder,'views'))
>              template = env.get_template(response.view)
>              return template.render(**d).encode('utf8')
>          else: return d
>      return _jinja2
>
> On Dec 26, 2008, at 3:54 AM, Massimo Di Pierro wrote:
>
> > Hi Italo,
>
> > I played with this some more. Try define the following decorator  
> > (in a model or controller)
>
> > def jinja2(f):
> >      def _jinja2():
> >            d=f()
> >            if isinstance(d,dist):
> >            from jinja2 import Environment, FileSystemLoader
> >            env = Environment(loader=FileSystemLoader(os.path.join
> > (request.folder,'views',request.controller))
> >            template = env.get_template(response.view)
> >            return template.render(**d).encode('utf8')
> >      return _jinja2
>
> > Those controller actions marked with decorator @jinja2 will expect  
> > a Jinja2 view instead of a web2py view. Mind that you must create a  
> > view file for @jinja2.
> > Keep me posted on whether this works or you encounter any issue.  
> > Example
>
> > @jinja2
> > def index(): return dict(hello='world')
>
> > with FILE: yourapp/views/default/index.html BEGIN
> > Hello {{ hello }}
> > END
>
> > should make "Hello world".
>
> > Massimo
>
> > P.S. I am ccing the list since others may be interested

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to