You can store your variables in the session storage object.

On Jul 12, 7:56 am, Tim Michelsen <[email protected]> wrote:
> Hello web2py folks,
> what is the preferred way to exchange parameters or variables between
> views and controllers?
>
> I have a page where a form gathers input and then a plot is generated
> according to these inputs.
>
> I am currently using the following setup:
>
> ## in VIEW
> <h2>Input form</h2>
>   {{=form}}
> <h2>Submitted variables</h2>
> {{=(request.vars.number, request.vars.hold)}}
>
> <center>
>    <img  src="{{=URL(r=request,f='image_mat_form',
> args=[request.vars.number, request.vars.hold])}}"/>
>    <!--
>    <img src="{{=URL(r=request,f='image_pil')}}"/>
>    -->
> </center>
>
> # in CONTROLLER
> def plot():
>
>      form=FORM(TABLE(TR("Your number:",INPUT(_type="text",
> _name="number",requires=IS_FLOAT_IN_RANGE(0, 10))),
>                      TR("Overlay new
> curves:",INPUT(_type="checkbox",_name="hold", value=False)),
>                      TR("",INPUT(_type="submit",_value="SUBMIT"))))
>      if form.accepts(request.vars,session):
>          response.flash="form accepted"
>      elif form.errors:
>          response.flash="form is invalid"
>      else:
>          response.flash="please fill the form"
>      return dict(form=form,vars=form.vars)
>
> def image_mat_form():
>      number = float(request.args[0])
>      hold = request.args[1]
>      if hold == 'on':
>          hold_check = True
>      else:
>          hold_check = False
>
>      import sys
>      import matplotlib as mpl
>      mpl.use('Agg')
>
>      #    from pylab import plot, savefig, legend, hold
>      import matplotlib.pyplot as plt
>      import numpy as np
>      import scipy as sp
>      import scipy.stats as st
>
>      plt.hold(hold_check)
>      t = np.arange(0.0 , 5.0, 0.05)
>      s1 = np.sin(number * np.pi * t )
>      s2 = s1 * np.exp(-t)
>
>      plt.plot(t, s1, 'g--o', t, s2, 'r:s' )
>      plt.legend(('sine wave ', 'damped exponential'))
>
>      # plot([1, 2 , number])
>      response.headers['Content-Type']="image/png"
>      plt.savefig(response.body)
>
>      return response.body.getvalue()
>
> is there a better option for exchanging the form data than
> args=[request.vars.number, request.vars.hold] -> number =
> float(request.args[0]), hold = request.args[1]?
> I will extend this and the "request.vars" will be many more.
>
> Please tell if you do not understand my question.
>
> Also I'd like to know how to add a file upload field to a FORM.
>
> Thanks in advance,
> Timmie
>
> Reference:
> Subject: [web2py:26240] Re: how can i write a PIL image object to 
> responsehttp://permalink.gmane.org/gmane.comp.python.web2py/13567
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to