Django模板中的功能 [英] functions in django templates

查看:65
本文介绍了Django模板中的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

django模板支持功能吗?

我可以在模板中内联编写它们吗?

如果可以,如何?

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

推荐答案

否。 Django模板的想法是它们仅显示信息(或多或少)。必须在其他位置定义更复杂的构造(例如函数)。

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

但是,您可以创建自己的模板标签或模板过滤器(在Python代码中),然后在自己的代码中使用模板。它们有点像功能。不过,它们的定义不在您的模板之内。

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.

您可以在django 文档

You can read about it in django documentation

这篇关于Django模板中的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆