Answer the question
In order to leave comments, you need to log in
How to use the results of one method call in different places in the template?
Hello!
I use Django3 and its default template engine. I added a method to the model that generates a random number from 0 to 100. Calling the method three times in different places of the same template, I see that it generates three different numbers. It turns out that if the method contained a query to the database, then they would be executed three times? If yes, then how to write methods or how to call them in a template so that the code is executed once?
Answer the question
In order to leave comments, you need to log in
Call a method on the view and pass its result to the template context.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question