template, static files, routes.py

17 views
Skip to first unread message

Sujan Shakya

unread,
Jan 6, 2010, 7:13:46 AM1/6/10
to web2py-users
I have some questions that I have not understood.

In layout.html, I found only one {{include}}.
Is it possible to use more {{include}} in layout.html so that we can
achieve equivalent of the following:
{% block head %}{% endblock %}
{% block content %}{% endblock %}
{% block col3 %}{% endblock %}


How are the static files served in production servers? Are they served
thru apache/lighttpd or web2py itself ?

And why is it that the use of routes.py not preferred?

Thanks.

Message has been deleted

mdipierro

unread,
Jan 6, 2010, 10:36:07 AM1/6/10
to web2py-users
Yes and no. the web2py template language is very different from
Django's because everything inside {{...}} is pure python. This means
there is no concept of blocks but in python you have function calls.

You can do

#based.html
{{def something()}}text goes here{{return}}
{{extend 'layout.html'}}
Hello world

#layout.html
<html><body>
<h1>{{something()}}<h1>
{{include}}
</body></html>

The def defines a funciton that you can use as a block.

Thadeus Burgess

unread,
Jan 6, 2010, 1:51:02 PM1/6/10
to web...@googlegroups.com
Massimo,

This does not work.

Especially if you are wanting a default for {{something()}}

It always uses the first definition, because of how views are extended
and included.

So as long as you have the def something(): and {{something()}} in the
same template file, it will work, but going through "extend" and
{{include}} it will not work.

We discussed this and you were going to see if there was a way to
accomplish this, but never heard anything about it.

-Thadeus

> --
> You received this message because you are subscribed to the Google Groups "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
>
>
>
>

KMax

unread,
Jan 6, 2010, 2:07:22 PM1/6/10
to web2py-users
I just check layout.html and found there place for menu.
So it should not be the issue to plase at layout.html code like
{{=myhead()}} and only issue will be valid return of myhead().
is it?

mdipierro

unread,
Jan 6, 2010, 2:56:34 PM1/6/10
to web2py-users
I think if you have a default you have to do

{{try:}}{{something()}}{{except:}}default value{{pass}}

Yes this is ugly. I am open to suggestions.

On Jan 6, 12:51 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> Massimo,
>
> This does not work.
>
> Especially if you are wanting a default for {{something()}}
>
> It always uses the first definition, because of how views are extended
> and included.
>
> So as long as you have the def something(): and {{something()}} in the
> same template file, it will work, but going through "extend" and
> {{include}} it will not work.
>
> We discussed this and you were going to see if there was a way to
> accomplish this, but never heard anything about it.
>
> -Thadeus
>

mdipierro

unread,
Jan 6, 2010, 2:57:38 PM1/6/10
to web2py-users
Mind that if you have

{{def a()}}hello{{return 'world'}}

then

{{a()}} prints renders as 'hello' but {{=a()}} renders as 'helloworld'

Massimo

Thadeus Burgess

unread,
Mar 30, 2010, 2:02:41 PM3/30/10
to web...@googlegroups.com
Alright, look at this example. "helloworld" always gets printed, the
function is not being redefined as expected. This is a simple example,
but in theory I would use this for say the websites sidebar not the
page title...

Any suggestions I have require changes to gluon and add support for blocks.

## layout.html
{{def title():}}
helloworld
{{pass}}

<body>
<h1>{{title()}}</h1>
<div id="content">{{include}}</div>
</body>

## view.html
{{extend 'layout.html'}}

{{def title():}}
I Like Pie
{{pass}}

Hello, Did you know that I like Pie... also.. The Cake Is A Lie!

I expect my title to be I Like Pie... but really my title is helloworld

-Thadeus

mdipierro

unread,
Mar 30, 2010, 6:02:40 PM3/30/10
to web2py-users
{{def title():}}
helloworld
{{return}}

On Mar 30, 1:02 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> Alright, look at this example. "helloworld" always gets printed, the
> function is not being redefined as expected. This is a simple example,
> but in theory I would use this for say the websites sidebar not the
> page title...
>
> Any suggestions I have require changes to gluon and add support for blocks.
>
> ## layout.html
> {{def title():}}
> helloworld
> {{pass}}
>
> <body>
> <h1>{{title()}}</h1>
> <div id="content">{{include}}</div>
> </body>
>
> ## view.html
> {{extend 'layout.html'}}
>
> {{def title():}}
> I Like Pie
> {{pass}}
>
> Hello, Did you know that I like Pie... also.. The Cake Is A Lie!
>
> I expect my title to be I Like Pie... but really my title is helloworld
>
> -Thadeus
>

Reply all
Reply to author
Forward
0 new messages