On Saturday, July 11, 2015 at 5:10:32 PM UTC-4, PRACHI VAKHARIA wrote: > > > > > Dear Anthony, > > That was not only insightful and helpful, but it also solved my problem. I > used the third solution recommended, since it keeps the view files intact > and independent. > *Thank you very much.* > > I learned that {{extend}} and {{include}} are not python code and that > they are executed before Python code is run – that was really great to know > and learn. And hence, how {{extend}} cannot be put inside a python "if" > block – which is what I had been trying to do. > > > *""The only drawback to this approach is that you cannot compile such a > view because the value of the Python expression will only be known at > runtime, not at compile time.""* > > Q: Why is that a drawback, if I may ask? How does compiling a view html > file help? > > When a view is executed, first it is parsed and converted to pure Python code (all the non-Python lines in the template are wrapped in calls to response.write). Then the resulting Python code is executed in order to write the final HTML to the response body. A compiled view has already been parsed to the final Python code (including and include/extend statements) and then converted to Python bytecode (i.e., a .pyc file), so when executed, the parsing and bytecode steps are skipped, which greatly speeds up execution. In production, it is recommended that you compile the whole app (controllers and views are compiled to bytecode as well, though there is an additional benefit to compiling the views, because you also get to skip the parsing step).
*Q: Which is the more effective and efficient method among the methods 1 > and 3 **(look below)**?* > > I would lean toward method 3 because it allows you to compile the views, and it might end up being simpler, as it will likely only require a few if blocks in the layout rather than adding a conditional extend expression to every view. Of course, it depends on the use case -- if you're dealing with only one such view, methods 1 or 2 might be a simpler approach. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.