Generally speaking, django doesn’t encourage any code going into the templates . It tries to limit what goes in there into fairly declarative type statements. The goal is to put all the logic into the model, view, and other python code, and just reference the pre-calculated values from the templates.
Read moreHow do I start Django code?
Your First Steps With Django: Set Up a Django Project
Read more