Custom template tags and filters
Code layout
Custom template tags and filters must live inside a Django app. If they relate to an existing app it makes sense to bundle them there; otherwise, you should create a new app to hold them.
The app should contain a templatetags directory, at the same level as models.py, views.py, etc. If this doesn’t already exist, create it - don’t forget the init.py file to ensure the directory is treated as a Python package. After adding this module, you will need to restart your server before you can use the tags or filters in templates.
Your custom tags and filters will live in a module inside the templatetags directory. The name of the module file is the name you’ll use to load the tags later, so be careful to pick a name that won’t clash with custom tags and filters in another app.
For example, if your custom tags/filters are in a file called poll_extras.py, your app layout might look like this:
polls/
init.py
models.py
templatetags/
init.py
poll_extras.py
views.py
And in your template you would use the following:
{% load poll_extras %}
Custom template tags and filters的更多相关文章
- [Javascript] Format console.log with CSS and String Template Tags
The Chrome console allows you to format messages using CSS properties. This lesson walks you through ...
- The Django template language 阅读批注
The Django template language About this document This document explains the language syntax of the D ...
- [django]添加自定义template filter标签
看文档templatetag 直接放在app下的templatetag 文件夹下就好,这里想放到一个公共的目录下,然后写下简单的自定义tag的模板. django1.6 创建 在项目目录下建立如下的文 ...
- python 学习笔记十八 django深入学习三 分页,自定义标签,权限机制
django Pagination(分页) django 自带的分页功能非常强大,我们来看一个简单的练习示例: #导入Paginator>>> from django.core.p ...
- Django 2.0.1 官方文档翻译: 文档目录 (Page 1)
Django documentation contents 翻译完成后会做标记. 文档按照官方提供的内容一页一页的进行翻译,有些内容涉及到其他节的内容,会慢慢补上.所有的翻译内容按自己的理解来写,尽量 ...
- explain the past and guide the future 好的代码的标准:解释过去,指引未来;
好的代码的标准:解释过去,指引未来: Design philosophies | Django documentation | Django https://docs.djangoproject.co ...
- Django中的自定义过滤器
一.为什么要自定义Django中的自定义过滤器:Django中提供了很多内置的过滤器和标签,详见链接django官网,主要有以下几个: autoescape(自动转义)block(模板继承)csrf_ ...
- The template engine
Play has an efficient templating system which allows to dynamically generate HTML, XML, JSON or any ...
- django第一篇
摘要: 1 Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的软件设计模式,即模型M,视图V和控制器C.模型即后端逻辑,视图就是url对应的前端展示 2本文简介了使用模型 ...
随机推荐
- SilkTest天龙八部系列1-初始化和构造函数
SilkTest没有提供专门的构造函数机制,但是在类对象生成的过程中,会先初始化在类中申明的变量.我们可以在初始化该变量的时, 调用某些函数完成对象初始化工作,看上去好像是调用了构造函数一样.不过要记 ...
- Bash String Manipulation Examples – Length, Substring, Find and Replace--reference
In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...
- oracle pde文件导入
pde使用pl/sql developer的tools->import tables->pl/sql developer来导入
- iOS类初始化
类继承下来的初始化有三种: +(void)load: +(void)initialize: -(instancetype)init: +(void)load:会自动调用(也可手动调用),只要有引用 ...
- Eclipse启动Tomcat访问不了首页
Eclipse开发web项目与myEclipse不同: 启动服务器后访问 http:localhost:8080 找不到服务器 想要访问Tomcat首页只需修改Tomcat配置 进入Eclipse双击 ...
- WPF翻转动画
在WPF中要翻转对象,估计是得用三维变换,所以我用到了AxisAngleRotation3D,让图形绕着Z轴来旋转. 先看看效果. 是的,就是这样的效果,在XAML中,由于涉及三维图形,我先做了两个用 ...
- LUN 和 LVM 知识
LUN是对存储设备而言的,volume是对主机而言的. lun是指硬件层分出的逻辑盘,如raid卡可以将做好的400G的raid5再分成若干个逻辑盘,以便于使用,每一个逻辑盘对应一个lun号,OS层仍 ...
- 【排障】每次打开word都提示要安装配置
为什么每次打开word都提示要安装配置?很多人在打开word时,总是提示要安装配置一遍,花去不少时间,这是由于电脑里有两个不同版本的office软件,产生的原因可能是原来的卸载了没卸载干净,或是安装了 ...
- delta simulation time[(delta cycle), (delta delay)]
"Delta cycles are an HDL concept used to order events that occur in zero physical time."si ...
- YII数据库操作(CURD操作)
数据库操作 获得模型对象 $model = 模型名::model();或$model = new 模型名(); 1.查询多条记录(返回值:二维数组) $result = $model->find ...