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本文简介了使用模型 ...
随机推荐
- hdu 3183 A Magic Lamp(RMQ)
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...
- (8)Launcher3客制化之ContentProvider内容提供者,实现其它应用改动数据库更新等操作
首先加入两个权限 <uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" ...
- 牛一网ecshop家电数码模板(仿易迅网)for ecshop 2.7.3
本模板尤其适用于家电数码行业. 本模板已经开发.测试完毕,并开放演示. 本模板支持全站静态.销售数量后台自定义.首页商品独立图片.品牌独立展示.商品精美团购.宽屏窄屏自动识别并切换.分 ...
- android开发Proguard混淆与反射
http://charles-tanchao.diandian.com/post/2012-05-24/20118715 由于前面开发数据操作类,所以利用反射,封装了一个BaseDao,本来在平常的时 ...
- jquery选择器及效率问题
$('p2') //选择名字 $('.class') //选择class $('#id') //选择id $('#id li') //所有id=”id”标签内的li标签 $(“#id”).find(“ ...
- 多媒体应用-swift
照片选择主要是通过UIImagePickerController控制器实例化一个对象,然后通过self.PresentViewController方法推出界面显示.需要实现代理UIImagePicke ...
- oracle学习----特殊的连接方式
1.笛卡儿积 merge join cartesion SQL> select ename,dname from emp,dept; 已选择56行. 执行计划------------------ ...
- c基础语法
1 连续写两个分号,第2个分号就是一条空语句,空语句实际是什么也不做,语法是正确的,编译不会出错. 空语句可以增加程序的可读性,可以作为待写的函数体.循环体.语句块.所以,空语句是可以有用的. 2 s ...
- iOS 跳转至 指定 StoryBoard 中 指定的 Scene
UIStoryboard *stryBoard=[UIStoryboard storyboardWithName:@"second" bundle:nil]; UIViewCont ...
- 20160331javaweb之JSP include 指令&&九大隐式对象
3.零散知识 (1)jsp映射 <servlet> <servlet-name>index</servlet-name> <jsp-file>/inde ...