It works.

On Tuesday, August 23, 2011 8:46:39 AM UTC-4, Henri Heinonen wrote:

> Give it a shot, if you will: http://fsi.it.jyu.fi/animation 
>
> On Aug 23, 3:45 pm, Henri Heinonen <henri.h...@gmail.com> wrote: 
> > Thank you! It works. :) 
> > 
> > On Aug 23, 3:40 pm, Anthony <abas...@gmail.com> wrote: 
> > 
> > > In index(), the value of 'image' ends up being the URL 
> > > '/cavityflow/default/cavityflow_plot', which is not the URL of the 
> image you 
> > > want to load. Instead, that URL itself ultimately just returns another 
> URL, 
> > > '/cavityflow/static/images/cavityflow.gif'. So, your img src attribute 
> is 
> > > pointing to a string representation of the URL of the image, not the 
> image 
> > > itself. 
> > 
> > > Instead, just have the index function create the image in 
> /static/images, 
> > > and use the image URL as the src attribute, like this: 
> > 
> > > def index(): 
> > >     [snip] 
> > >     if form.accepts(request.vars, session, keepvalues=True): 
> > >         [snip] 
> > >         cavityflow_plot()  # this creates the image and saves it in the 
>
> > > static folder 
> > >         image=URL('static','images/cavityflow.gif') 
> > >     return dict(form=form, image=image) 
> > > Note, as is, the cavityflow_plot() function is accessible as a URL. 
> Since 
> > > you are only using it internally and probably do not need/want to it be 
>
> > > accessible via URL, you should either give it at least one argument or 
> > > precede its name with a double underscore (controller functions that 
> take 
> > > arguments or start with a double underscore are not publicly exposed -- 
> seehttp://web2py.com/book/default/chapter/04#Dispatching). 
> > 
> > > Anthony 
> > 
> > > On Tuesday, August 23, 2011 6:02:51 AM UTC-4, Henri Heinonen wrote: 
> > > > Ok. 
> > 
> > > > This is the default/index.html: 
> > > > {{extend 'layout.html'}} 
> > > > <h1>cavityflow</h1> 
> > > > {{=form}} 
> > > > {{if image:}} 
> > > > <hr /> 
> > > > <h2>Constants</h2> 
> > > > <p>These are the constants that were used during the simulations.</p> 
>
> > > > {{=BEAUTIFY(request.vars)}} 
> > > > <h2>Figure</h2> 
> > > > <img src="{{=image}}" alt="loading..."/> 
> > > > {{pass}} 
> > 
> > > > This is the default.py: 
> > > >http://pastebin.com/VGE69RG1 
> > 
> > > > Does this work for you? 
> > 
> > > > On Aug 22, 1:10 pm, Henri Heinonen <henri...@gmail.com> wrote: 
> > > > > default/index.html: 
> > > > > {{extend 'layout.html'}} 
> > > > > <h1>cavityflow</h1> 
> > > > > {{=form}} 
> > > > > {{if image:}} 
> > > > > <hr /> 
> > > > > <h2>Figure</h2> 
> > > > > <img src="{{=image}}" alt="loading..."/> 
> > > > > {{pass}} 
> > 
> > > > > default.py: 
> > > > > def index(): 
> > > > >     form=FORM('nx:', INPUT(_name='nx', _value=20.0), BR(), 'ny:', 
> > > > > INPUT(_name='ny', _value=20.0), BR(), 'nt:', INPUT(_name='nt', 
> > > > > _value=100.0), BR(), 'nit:', INPUT(_name='nit', _value=100.0), 
> BR(), 
> > > > > 'dt:', INPUT(_name='dt', _value=0.01), BR(), 'vis:', 
> > > > > INPUT(_name='vis', _value=0.1), BR(), 'rho:', INPUT(_name='rho', 
> > > > > _value=1.0), BR(), INPUT(_type='submit',_value='Make figure')) 
> > 
> > > > >     image=None 
> > > > >     if form.accepts(request.vars, session, keepvalues=True): 
> > > > >         session.flash = 'Form accepted.' 
> > > > >         session.nx=float(request.vars.nx) 
> > > > >         session.ny=float(request.vars.ny) 
> > > > >         session.nt=float(request.vars.nt) 
> > > > >         session.nit=float(request.vars.nit) 
> > > > >         session.dt=float(request.vars.dt) 
> > > > >         session.vis=float(request.vars.vis) 
> > > > >         session.rho=float(request.vars.rho) 
> > > > >         image=URL(r=request,f='cavityflow_plot') 
> > > > >     return dict(form=form, image=image) 
> > 
> > > > > def cavityflow_plot(): 
> > > > >     return cavityflow(session.nx, session.ny, session.nt, 
> session.nit, 
> > > > > session.dt, session.vis, session.rho) 
> > 
> > > > > def cavityflow(nx, ny, nt, nit, dt, vis, rho): 
> > > > > ...*clip* *clip* ... # Here the application will make one hundred 
> png 
> > > > > images. 
> > > > >            os.system("convert *.png cavityflow.gif") 
> > > > > # What do I need to add in here in order to return the 
> cavityflow.gif 
> > > > > onto the webpage of my application? 
> > 
> > > > > The question is in the source code as a comment line. 
> > 
> > > > > Yours sincerely, Henri Heinonen. 
> > 
> >

Reply via email to