Django里面的自定义tag和filter

Django的文档里面有这么一句

The app that contains the custom tags must be in INSTALLED_APPS 
in order for the {% load %} tag to work. 

当第一次load一个template的时候,调用源码

def get_templatetags_modules():
    """
    Return the list of all available template tag modules.

    Caches the result for faster access.
    """
    global templatetags_modules
    if not templatetags_modules:
        _templatetags_modules = []
        # Populate list once per process. Mutate the local list first, and
        # then assign it to the global name to ensure there are no cases where
        # two threads try to populate it simultaneously.
        for app_module in ['django'] + list(settings.INSTALLED_APPS):
            try:
                templatetag_module = '%s.templatetags' % app_module
                import_module(templatetag_module)
                _templatetags_modules.append(templatetag_module)
            except ImportError:
                continue
        templatetags_modules = _templatetags_modules
    return templatetags_modules

Load类型的Node 输出的定义

class LoadNode(Node):
    def render(self, context):
        return ''
可见他是一个空白字符串,也就是在输出的html中"抹掉"了


example

<html>
<head>
	{% load blog_extras %}
	Hi my double value is <b>{{myvalue|mycut}}</b>
</head>
</html>

will be tokenized as



Then the block token will be set to LoadNode, var token to Variable Node  in my case, done byParser

最后把每一个node render出来

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值