Home > other >  How to pass the value from a function in Django
How to pass the value from a function in Django

Time:07-26

In views.py I have the following code:

def basic(request):
    n_objetos=request.POST['n_objetos']
    peso_maximo=request.POST['peso_maximo']

    if n_objetos.isdigit() and peso_maximo.isdigit():
        a=int(n_objetos)
        b=int(peso_maximo)
        print(a)
        return render(request, 'valores.html', {'n_objetos': a, 'peso_maximo': b})
    else:
        res='Apenas numero.'
        return render(request, 'valores.html', {'res': res})

Here everything is great, but the next step is being the problem. In the next step I want to use both integer values a and b, they were returned in render {'n_objetos': a, 'peso_maximo': b}, but I don't know how to do this. I need to use them in other functions but I have no ideia how to do this.

CodePudding user response:

Either set them as globals or make this function inside a class

CodePudding user response:

Actually you have some ways to handle this situation.

1- Store those values in hidden inputs for your next request. That way the user won't be able to see those inputs.

2- You could use some sort of data base or external file.

3- Send those values inside a cookie.

I hope it work for you :)

  • Related