More and more stuff in trunk

162 views
Skip to first unread message

mdipierro

unread,
Nov 1, 2009, 1:02:12 AM11/1/09
to web2py-users
If you want to use the template system or the DAL from any python
program (now web2py):

1) make sure web2py/ is in path

2) HOW TO DAL:

from gluon.sql import DAL, Field

db=DAL('sqlite://storage',folder='/path/to/a/file/where/to/store/
db')
db.define_table(...)
... etc etc

3) HOW TO templates:

from gluon.template import render

page = render(content="{{for i in range(n):}}Hello
{{pass}}",context=dict(n=5))
print page

instead of content you can pass a stream

page = render(stream=open('myview.html','rb'),context=dict(n=5))

or a filename

page = render(filename='myview.html',context=dict(n=5))

If the template contains a {{import...}} or {{extend...}} you should
also pass a path

page = render(...., path='./')

telling web2py where to look for included and extended files.

If you try any of these please let us know.

Massimo
Reply all
Reply to author
Forward
0 new messages