I'm trying to do this from the web2py shell, and I get the following
error:
>>> response.render('default/index.html2',context=dict(message="hello"))
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/gwarner/web2py/gluon/globals.py", line 128, in render
run_view_in(self._view_environment)
File "/home/gwarner/web2py/gluon/compileapp.py", line 338, in
run_view_in
restricted(ccode, environment, layer)
File "/home/gwarner/web2py/gluon/restricted.py", line 115, in
restricted
raise RestrictedError(layer, code, '', environment)
RestrictedError: <gluon.restricted.RestrictedError instance at
0x7f632b8c>
As you can see, I'm trying to use the template "index.html2", which is
the same as the default index.html, except I've moved the {{=message}}
outside of the try statement.
Is it possible to do what I'm trying to do from the shell?
> > > > > > > > > > from gluon.templateimport parse_template
> > > > > > > > > > from gluon.tool import Mail
>
> > > > > > > > > > mail=Mail
> > > > > > > > > > mail.settings.server='
smtp.gmail.com:
> > > > > > > > > > 587'
> > > > > > > > > > mail.settings.sender='...@
somewhere.com'
> > > > > > > > > > mail.settings.login=None or
> > > > > > > > > > 'username:password'
>
> > > > > > > > > > path=os.path.join(request.folder,"views")
> > > > > > > > > > context=dict(a=1,b=2,c=3,etc="etc")
> > > > > > > > > > message=parse_template('file.html',path=path,context=context)
> > > > > > > > > > mail.send(to=['...@
whatever.com'],subject='None',message=message)
>
> > > > > > > > > > Massimo
>
> > > > > > > > > > On May 27, 4:28 am, Carl <
carl.ro...@gmail.com> wrote:
>
> > > > > > > > > > > web2py's templating for HTML pages makes managing page structure
> > > > > > > > > > > populated with dynamic content very straightforward and scalable.
>
> > > > > > > > > > > What approach is recommended to use this power to manage emails/email
> > > > > > > > > > > templates?
>
> > > > > > > > > > > My application sends out emails populated with a lot of dynamic data
> > > > > > > > > > > and before I compose a String for the body text in Python I wondered
> > > > > > > > > > > if the existingtemplateengine could be harnessed (and if so, what's