On Sat, Dec 27, 2008 at 12:10 AM, mdipierro <[email protected]> wrote:
>
> Controllers do not see code in other controllers, for logical reasons,
> since they act on different requests.
> Controllers only see code in models. You need to put the code in a
> model file or in a module. If you put in a module you need to modify
> it so that request, response are passe to the decorator.
>
> About being pythonic.... I agree and disagree:
>
> You say
>
>> {{text|e}} <= pretty
>>
>> {{escape(text)}} <= not so much
>
> Fine but none of those examples is web2py-ese. This is the equivalent
> code in web2py:
>
> {{=text}}
>
> In web2py text is escaped by default. It is a MUST of security.
>
> You also say
>
>> pretty
>> {% for stuff in other_stuff %}
>> do stuff with {{stuff}}
>> {% endfor %}
>>
>> not so much
>> {{ for stuff in other_stuff }}
>> do stuff with {{=stuff}}
>> {{pass}}
>
> Again, none of those is valid web2py-ese. In web2py you do
>
> {{ for stuff in other_stuff: }}
> do stuff with {{=stuff}}
> {{pass}}
>
>  I find the second better because it uses python keywords instead of
> made up keywords (endfor?).
>
> The main problem I have with Django and Jinja is logical. Here is an
> example
>
> IN DJANGO:
>
> layout.html:
> <html><body><h1>{% block test %}nothing{% endblock %}</h1></body></
> html>
>
> index.html:
> {% extends 'layout.html %} hello {% block test %}world{% endblock %}
>
> renders as "<html><body><h1>world</h1></body></html>"
>
> Where does hello go? Logically this is a problem.
>
> IN WEB2PY
> layout.html:
> <html><body>{{include}}<h1>{{test()}}</h1></body></html>
>
> index.html:
> {{extend 'layout.html'}} hello {{def test():}}world{{return}}
>
> renders as "<html><body> hello <h1>world</h1></body></html>".
>
> The extending layout is {{include}}d in a specific point so any
> leftover text is inserted there. No text gets lost.
> Moreover in web2py blocks are functions (this is more pythonic) and I
> can even pass variables to them.
>
> Massimo
>

Most I agreed with Massimo. In Italo Maia email, he said he don't like
python code in template, but I like. Pure Python code is not beautiful
and it's not pythonic? You'll need to learn another template language
when you can use Python code in template. And you can even get all
powerful of Python. That's a great thing. Many template systems
support python code, except django one.

And rencently I'm working on making web2py template supports block tag
just like django. Say you have a parent template, looks like:

This base.html:

<html>
<head>
<title>{{block title}}Untitled{{end}}</title>
</head>
<body>
{{block main}}{{end}}
</body>
</head>

Here I defined two block title and main.

This is child template -- index.html:

{{extend "base.html"}}
{{block main}}<h1>Hello, Uliweb</h1>{{end}}

I defined main block, so when you render index.html, this main block
will replace the one defined in base.html. Because there is no title
block defined in index.html, so the title block defined in base.html
will be remained.

But use block support will break the {{include}} usage.

I'm using this new template module in my project uliweb. And the
module is in 
http://code.google.com/p/uliweb/source/browse/trunk/uliweb/core/template.py.
And I also made other changes, for example: parse_template will be
template_file, and the parameters are also different. But the syntax
of template tags are similar.

Maybe it's useful for someone.

-- 
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://uliwebproject.appspot.com
My Blog: (new)http://http://hi.baidu.com/limodou
(old)http://www.donews.net/limodou

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