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. PHP工具下载地址

    Zend Debugger下载地址:http://www.zend.com/en/products/studio/downloads 需要先注册一下,然后才能进行下载.

  2. STM32F030 IO口外部中断应用

    //==文件exit.h============================================================ #ifndef __EXIT_H #define __ ...

  3. win10系统调用架构分析

    http://blog.csdn.net/liuyez123/article/details/50992038

  4. 集合练习——Set部分

    我们知道list存储的是有序不唯一的元素. set存储的是无序唯一的元素. 那么下面看一个例子吧: package CollectionPart; import java.util.HashSet; ...

  5. Orcle11g用户密码恢复

    1.当安装Orcle11g后,很久不用,忘记了用户名和密码.可以通过以下方法重置: 如上图及重置用户sys,system密码为123

  6. javascript 中的new操作符的理解

    new 操作符 在有上面的基础概念的介绍之后,在加上new操作符,我们就能完成传统面向对象的class + new的方式创建对象,在Javascript中,我们将这类方式成为Pseudoclassic ...

  7. Android的Manifest配置文件介绍

    一.关于AndroidManifest.xml       AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(ac ...

  8. hdoj1325 Is It A Tree?

    Is It A Tree?题目链接 题意: 多组测试数据, 每组数据有多个数对, 表示一条有向边(即第一个数是第二个数的父节点), 以 0,0 为一组测试数据结束标志.当输入-1,-1时测试结束. 从 ...

  9. DDX_Text (MFC)

    DDX_Text (MFC) 描述:该DDX_Text功能管理int的转移,UINT,long,DWORD,CString,float, 或 double编辑控件之间的数据在对话框中,表单视图或控制视 ...

  10. asp.net:录入数据库的中文变问号

    表格是可以接受中文的: 类型也是nvarchar的: 还是出现写中文变问号?? 这时候请加入转义大写N: 如: 原查询语句:insert into table1(name)  values('蜘蛛侠' ...