How do I receive variables in Web2py?

-2

I'm starting with this framework I need help to make a calculator but I need to know how to capture a variable

    
asked by Josue Mendez 28.09.2017 в 01:35
source

2 answers

1

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

    
answered by 06.12.2018 в 00:14
0

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

    
answered by 05.02.2018 в 10:44