开发者

functions in django templates

开发者 https://www.devze.com 2023-02-16 03:53 出处:网络
Does django t开发者_高级运维emplates support functions? Can I write them inline within the template?

Does django t开发者_高级运维emplates support functions?

Can I write them inline within the template?

If I can, how?


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消