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出来
Django里面的自定义tag和filter的更多相关文章
- Django(模板语言-自定义filter和simple_tag)
Django(模板语言-自定义filter和simple_tag) filter过滤器的主要形式:变量|函数,意思是将变量交给函数处理,而自定义filter就是自己定义函数,因为用到已有的很少. ...
- Django中的自定义过滤器
一.为什么要自定义Django中的自定义过滤器:Django中提供了很多内置的过滤器和标签,详见链接django官网,主要有以下几个: autoescape(自动转义)block(模板继承)csrf_ ...
- Django模板之自定义过滤器/标签/组件
自定义步骤: 1. 在settings中的INSTALLED_APPS配置当前app,不然django无法找到自定义的simple_tag. 2. 在app应用中创建templatet ...
- jsp如何自定义tag的标签库?
虽然和上一次的使用自定义的tld标签简化jsp的繁琐操作的有点不同,但是目的也是一致的.自定义tag比较简单. 1.新建tag标签 在WEB-INF目录下新建一个tags的文件夹,是自定义tag标签的 ...
- ASP.NET Core MVC – 自定义 Tag Helpers
ASP.NET Core Tag Helpers系列目录,共四篇: ASP.NET Core MVC Tag Helpers 介绍 ASP.NET Core MVC – Caching Tag Hel ...
- Django关于设置自定义404和安装debug-toolbar的笔记
Django关于设置自定义404和安装debug-toolbar的笔记 关于设置404 先做好404页面,然后在views.py文件中做好映射,最后是在urls.py做好路由,而这个urls.py必须 ...
- 自定义tag标签-实现long类型转换成Date类型
数据库里存储的是bigint型的时间,entity实体中存放的是long类型的标签,现在想输出到jsp页面,由于使用的是jstl标签,而要显示的是可读的时间类型,找来找去有个 fmt:formatDa ...
- 第三百一十四节,Django框架,自定义分页
第三百一十四节,Django框架,自定义分页 自定义分页模块 #!/usr/bin/env python #coding:utf-8 from django.utils.safestring impo ...
- jsp中 自定义 tag的几种方式
在jsp文件中,可以引用tag和tld文件. 1.对于tag文件,使用tagdir引用(这个直接是引用的后缀tag文件的jsp文件) <%@ taglib prefix="ui&quo ...
随机推荐
- spring集成mongodb jar包版本问题
在开发过程中,spring集成mongodb的jar包. 如果需要使用排序功能. spring-data-mongodb-1.4.1.RELEASE.jar 的版本为1.4.1,如果使用如下代码: Q ...
- Scala基础入门-3
学习Scala——映射和元组 映射和和元组,也就是Maps和Tuples.Map这东西应该都挺明白的,就是键值对的集合.而元组,tuple,这东西并不是每个语言都有(Python中是有的,不过当时学的 ...
- bootstrap 3 のcheckbox-inline
<div class="form-group"> <p class="control-label"><b> ...
- Oracle字符编码
.检查服务器编码: 执行SQL语法: Java代码 select * from v$nls_parameters; 或 Java代码 select * from nls_database_parame ...
- AIX 命令大全
http://www.ahinc.com/aix/general.htm http://web.mit.edu/javadev/packages/Acme/ http://jparsec.codeha ...
- 第52周二Restful
今天去spring官网发现一个关键词:Restful,以前只在与一个系统对接时用到过这种形式的接口,但印象不深,百度搜索后才感觉自己太out了,这个概念2000年提出,2009年时国内就有很多人推荐使 ...
- 如何在Root的手机上开启ViewServer,使得HierachyViewer能够连接
前期准备: 关于什么是Hierarchy Viewer,请查看官方文档:http://developer.android.com/tools/debugging/debugging-ui.html.个 ...
- 习题3.4 & 3.5: 求两链表的交集和并集
#include<stdio.h> #include<stdlib.h> struct Node; typedef struct Node *PtrToNode; typede ...
- strlen、strcmp、strcat、strcpy、memcpy基础函数的实现
最近实习+投简历+琐事弄得自己忙的不行不行的,终于今天可以开始记录一些东西了... 1.strlen函数的实现 int strlen(const char *str){ assert(str!=NUL ...
- YBC中国国际青年创业计划
YBC中国国际青年创业计划 中国青年创业国际计划(简称YBC)是共青团中央.中华全国青年联合会.中华全国工商业联合会共同倡导发起的青年创业教育项目.该项目参考总部在英国的青年创业国际计划( Youth ...