django 模块 template(filter)
来源:互联网 发布:网络营销策划书例文 编辑:程序博客网 时间:2024/05/29 13:16
from django import templatefrom django.template.base import resolve_variableregister = template.Library()@register.filter('my_rong')def my_rong(a): return a+'rong'#html -> <h1>{{ item.name | my_rong }}</h1>#模版配置TEMPLATE_DIRS = ( os.path.join(BASE_DIR,'templates'), )#静态文件STATICFILES_DIRS = ( os.path.join(BASE_DIR,'static'), )#帮助方法:{{ item.event_start|date:"Y-m-d H:i:s"}}{{ bio|truncatewords:"30" }}{{ my_list|first|upper }}{{ name|lower }}通过simple_tag实现模版语言中的帮助方法a、在app中创建templatetags文件夹b、创建任意 .py 文件,如:xx.py#!/usr/bin/env python#coding:utf-8from django import templatefrom django.utils.safestring import mark_safefrom django.template.base import resolve_variable, Node, TemplateSyntaxErrorregister = template.Library()@register.simple_tagdef my_simple_time(v1,v2,v3): return v1 + v2 + v3c、在使用自定义simple_tag的html文件中导入之前创建的 xx.py 文件名 {% load xxx %}d、使用simple_tag {% my_simple_time 1 2 3%} {% my_input 'id_username' 'hide'%}e、再settings中配置当前app,不然django无法找到自定义的simple_tag INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app01', )
0 0
- django 模块 template(filter)
- django template filter
- django template 自定义filter的使用
- [django]添加自定义template filter标签
- Django template 中优雅的自定义权限过滤filter
- 在Django中自定义filter并在template中使用
- Django template
- Django template
- django template
- Django Template
- Django Template
- django template 基础(模板对象(Template),上下文对象(Context))
- Django 模板(template)中文乱码
- Django技术详解(四)开发template
- 深入学习Django源码基础11 - 简要分析Django中template模块1
- 深入学习Django源码基础12 - 简要分析Django中template模块2
- Django学习笔记(二)Django使用template
- django的template中怎样进行gbk到utf-8的转码,建立一个filter
- 编程规范
- HDOJ 2795 Billboard(线段树—找到线段树中>=给定值的第一个点并更新这个点)
- 浅谈spring
- 删除GoldenGate
- android CoordinatorLayout使用
- django 模块 template(filter)
- EvnetBus的原理和使用
- linux下安装jdk
- "网卡eth0,未识别的端口"的解决方法
- 红黑联盟 dos批处理延时技术
- 292. Nim Game
- 冒泡排序及算法优化
- linux ifconfig命令参数及用法详解--linux查看配置网卡命令
- 基于AFN框架的多图上传