Can I write Python code in Django?

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 more