thanks for reply.
Yes, I've showed 3 ways of checking if var was previously defined, but the question was about preferred way of doing that in Web2Py, also I want to add 'not empty' to this check.
> If you are the developer you should know what variables you are going to be using in the view?
It may happen that views are written by other people, etc, isn't it better to introduce as much independence as possible?
Here is my case, but I guess there may be other similar.
I keep content for my static pages in db. It is broken in parts like footer_block, header_block, content_block, etc.
And I use blocks in views, so I can fill parts of view with content from db, or leave them with default content from extended view (i.e. my version of layout.html) with {{super}}. Also, some part of page can be empty in db.
So, I thought that it would be a good idea to return only non-empty parts to the view, and in case when some part is empty in db, it will not be passed to the view, and content from extended layout will be used.
This is in the view that extends main template, this only checks if var is defined, but not if it is not empty.
{{block header_block}} {{try:}} {{=header_block or ''}} {{except:}} {{super}} {{pass}} {{end}}
Does it make sense?