码迷,mamicode.com
首页 > 其他好文 > 详细

Django自定义模板函数

时间:2018-04-19 20:01:51      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:import   ...   sim   ISE   文件夹   新建   模板函数   会计   targe   

https://www.cnblogs.com/SunsetSunrise/p/7680491.html

在django中新建一个应用:listpage
在listpage中新建templatetags文件夹
在templatetags文件夹中新建XX.py文件
在XX.py中写入:

from django import template

register = template.Library()


@register.simple_tag()
def YY(a,b):
    return a+b

  

在模板文件中写入

{% load XX %} <!--一定要写在第一行开头-->
...
{% YY 1 2 %} <!--函数会计算:1+2-->
...

  

运行模板,得到3

Django自定义模板函数

标签:import   ...   sim   ISE   文件夹   新建   模板函数   会计   targe   

原文地址:https://www.cnblogs.com/andy9468/p/8885680.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!