I'm starting with this framework I need help to make a calculator but I need to know how to capture a variable
I'm starting with this framework I need help to make a calculator but I need to know how to capture a variable
I'll explain how to add 2 numbers, from there you can make the calculator you want
first create a function in your Controller
, example:
def Sumar():
num1=0
num2=0
if request.post_vars:
num1=float(request.post_vars.num1)
num2=float(request.post_vars.num2)
total=num1+num2
return locals()
and in your view
create a form with two fields with name=num1
and name=num2
and button of type Submit
, remember to create the HTML with the name of the function in this case sum
You can access the variables just like you did in python. You have some web2py variables that you can access at any time. For example, access the id of the logged in user: auth.user.id For more information I recommend that you read the web2py book, where all your doubts will be clarified.
If you want to capture a form field: request.vars.fieldname or name_form.vars.fieldname