1

Does django templates support functions?
Can I write them inline within the template?
If I can, how?

0

2 Answers 2

3

No. The idea of Django templates is that they only display information (more or less). More complicated constructs (like functions) must be defined elsewhere.

But, you can create your own template tags or template filters (in Python code) and then use them in your template. They kind of act like functions. Their definition is not within your template, though.

You can read about it in django documentation

Sign up to request clarification or add additional context in comments.

Comments

3

You can call method without arguments: stackoverflow answer

You can do it by using (.) dot notation. read more about variables in Django reference

Use a dot (.) to access attributes of a variable. Technically, when the template system encounters a dot, it tries the following lookups, in this order:

Dictionary lookup
Attribute lookup
Method call
List-index lookup

Comments

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.