My mistake. Should have been

 >>> response.render('default/index.html2',dict(message="hello"))

or

 >>> response.render('default/index.html2',message="hello")

No "context=dict(...)". read more here

http://www.web2py.com/AlterEgo/default/show/225




On Jun 23, 11:14 am, Greg <gdwar...@gmail.com> wrote:
> 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?
>
> On May 28, 7:22 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Please try this:
>
> > def example():
> >     context= dict(one="1", two="2")
> >     message= response.render('default/example.html',context=context)
> >     print message
> >     return True
>
> > On May 28, 8:47 am, Carl <carl.ro...@gmail.com> wrote:
>
> > > thanks for your time Massimo.
>
> > > On May 28, 2:42 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > I see the problem.  There is something missing in my example. I will
> > > > fix this and resend it tomorrow.
>
> > > > Massimo
>
> > > > On May 28, 5:18 am, Carl <carl.ro...@gmail.com> wrote:
>
> > > > > small typo: I'm calling app/default/example rather than app/example
>
> > > > > On May 28, 11:17 am, Carl <carl.ro...@gmail.com> wrote:
>
> > > > > > thanks, that's very good of you.
>
> > > > > > I've implemented a zero-fat implementation to reproduce the 
> > > > > > behaviour
> > > > > > and remove my app's details...
>
> > > > > > In controllers\default.py I have:
>
> > > > > > def example():
> > > > > >     path=os.path.join(request.folder, 'views')
> > > > > >     context= dict(one="1", two="2")
> > > > > >     message= parse_template('default/
> > > > > > example.html',path=path,context=context)
> > > > > >     print message
> > > > > >     return True
>
> > > > > > In views\example.html I have 7 lines:
> > > > > > An example view for emails.
>
> > > > > > One = {{=one}}
>
> > > > > > Two = {{two}}
>
> > > > > > The end.
>
> > > > > > so I call app/example
> > > > > > and in my console I see this (from the print message statement):
> > > > > > response.write('An example view for emails.\r\n\r\nOne =
> > > > > > ',escape=False)
> > > > > > response.write(one)
> > > > > > response.write('\r\n\r\nTwo = ',escape=False)
> > > > > > two
> > > > > > response.write('\r\n\r\nThe end.',escape=False)
>
> > > > > > I'm running on WinXP but I don't think that's relevant here.
>
> > > > > > Hopefully you can either see the issue in my code or at least
> > > > > > reproduce the behaviour using the code supplied.
>
> > > > > > Carl
>
> > > > > > On May 28, 12:42 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > > can you post an example? I am confused.
>
> > > > > > > On May 27, 5:15 pm, Carl <carl.ro...@gmail.com> wrote:
>
> > > > > > > > it's got me puzzled too.
>
> > > > > > > > the text I have in my view is used but it's prefixed 
> > > > > > > > response.write(
> > > > > > > > and carriage returns are converted to \r\n
>
> > > > > > > > a dict in my view is displayed in emails as
> > > > > > > > response.write(absurl)
>
> > > > > > > > C
>
> > > > > > > > mdipierro wrote:
> > > > > > > > > ?
>
> > > > > > > > > why response.write( ... escape=False) ?
>
> > > > > > > > > On May 27, 12:13 pm, Carl <carl.ro...@gmail.com> wrote:
> > > > > > > > > > I've implemented the code but am one step away from a 
> > > > > > > > > > working
> > > > > > > > > > solution.
>
> > > > > > > > > > The variable message contains text "response.write( ... 
> > > > > > > > > > escape=False)"
> > > > > > > > > > for each section of text and for each dictionary item I use 
> > > > > > > > > > in my
> > > > > > > > > > view.
>
> > > > > > > > > > any thoughts?
>
> > > > > > > > > > C
>
> > > > > > > > > > On May 27, 12:16 pm, mdipierro <mdipie...@cs.depaul.edu> 
> > > > > > > > > > wrote:
>
> > > > > > > > > > > You can use the web2pytemplatelanguage to generate emails.
>
> > > > > > > > > > > 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
> > > > > > > > > > > > the recommended way to leverage it)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to