1

I'm having some difficulty returning multiple values in my view. I can create a model, store the values in the model, and then return it, but this approach is not what I'm looking for because these values will be used once only.

Is it possible to return multiple values without storing them in a model?

For example, view.py:

loanAmount = request.GET.get('desired_loan')
repaymentTime = request.GET.get('repayment_time')
return render(request, 'blog/draw.html', "I want to return loanAmount and repaymentTime")

and then in Template, simply:

{{ loanAmount }}

How do I go about this? Any direction or help will be appreciated.

Thanks,

1 Answer 1

6

I don't understand your sample code here. The third parameter to render is a dictionary, and you can have as many items as you like in it.

return render(request, 'blog/draw.html', {'loanAmount': loanAmount, 'repaymentTime': repaymentTime})
Sign up to request clarification or add additional context in comments.

2 Comments

OK, sorry for the vague question. I did not know you could have many items. Thanks a lot, that answers my question. Do I call it by {{ loanAmount }}?
Yes, the key is what you'll use in the template i.e. 'loanAmount' - it doesn't has to be same as the variable name. 'loanAm': loanAmount is also valid, in this case you'll be using loanAm in the template - {{ loanAm }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.