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的更多相关文章

  1. [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 ...

  2. The Django template language 阅读批注

    The Django template language About this document This document explains the language syntax of the D ...

  3. [django]添加自定义template filter标签

    看文档templatetag 直接放在app下的templatetag 文件夹下就好,这里想放到一个公共的目录下,然后写下简单的自定义tag的模板. django1.6 创建 在项目目录下建立如下的文 ...

  4. python 学习笔记十八 django深入学习三 分页,自定义标签,权限机制

    django  Pagination(分页) django 自带的分页功能非常强大,我们来看一个简单的练习示例: #导入Paginator>>> from django.core.p ...

  5. Django 2.0.1 官方文档翻译: 文档目录 (Page 1)

    Django documentation contents 翻译完成后会做标记. 文档按照官方提供的内容一页一页的进行翻译,有些内容涉及到其他节的内容,会慢慢补上.所有的翻译内容按自己的理解来写,尽量 ...

  6. explain the past and guide the future 好的代码的标准:解释过去,指引未来;

    好的代码的标准:解释过去,指引未来: Design philosophies | Django documentation | Django https://docs.djangoproject.co ...

  7. Django中的自定义过滤器

    一.为什么要自定义Django中的自定义过滤器:Django中提供了很多内置的过滤器和标签,详见链接django官网,主要有以下几个: autoescape(自动转义)block(模板继承)csrf_ ...

  8. The template engine

    Play has an efficient templating system which allows to dynamically generate HTML, XML, JSON or any ...

  9. django第一篇

    摘要: 1 Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的软件设计模式,即模型M,视图V和控制器C.模型即后端逻辑,视图就是url对应的前端展示 2本文简介了使用模型 ...

随机推荐

  1. cmd 控制台 提示:请求的操作须要提升!

    cmd 控制台 提示:请求的操作须要提升! 在windows7中想用route add 或相关route等命令须要以管理员身份执行,假设windows7以下没有以管理身份执行那么加入路由时候route ...

  2. Android记录6--ViewPage+Fragment的使用例子

    Android记录6--ViewPage+Fragment的使用例子 2013年9月6日Fragment学习 Fragment这个东西,我到现在才接触到,之前没有用到过,关于Fragment这个东西在 ...

  3. redhat 6 配置 yum 源的两种方法

      由于 redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装,再配置其他源. 本文包括配置本地源及第三方源.第三方源包括:网易,epe ...

  4. 快速高效的破解MySQL本地和远程密码

    http://www.kankanews.com/ICkengine/archives/212.shtml 快速的 MySQL 本地和远程密码破解!首先需要对数据库维护人员说明的是,不必紧张,你无需修 ...

  5. 玩转Android之在线视频播放控件Vitamio的使用

    其实Android中自带的MediaPlayer本身就能播放在线视频,MediaPlayer结合SurfaceView播放在线视频也是不错的选择(如果你没有性能或者用户体验上的要求),关于MediaP ...

  6. fuck'em

    不要说GUNGHO的游戏,连逆转三国这种都没玩过,还是做手游的,表现的那么冠冕堂皇,还不只是个常规的做软件的而已.只是以做软件的程度来做游戏,能做出的是个JB.

  7. Java strictfp关键字

    保证浮点运算的结果不受平台的影响,在任何平台上,使用统一的标准进行浮点运算,提高程序的可移植性(毕竟结果更可控,更精确),相应的,以降低性能为代价 Strictfp ensures that you ...

  8. <video>和<audio>标签

    一.<video>基本格式: <video width=" " heigh="" src=""> </vide ...

  9. count()与sum()

    介绍Mysql中的count()与sum()区别 CREATE TABLE `result` ( `name` varchar(20) default NULL, `subject` varchar( ...

  10. 万网免费主机wordpress快速建站教程-域名绑定及备案

    进入主机管理界面,点击管理 点击域名绑定,绑定域名项选择已有域名,选择已购买的域名,点击一键解析域名,点击添加,即可完成域名解析工作. 由于没有备案,备案状态显示为未备案,点击旁边的备案链接,跳转至阿 ...