开发者

functions in django templates

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜