django tag
官方文档:https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#simple-tags
stackoverflow demo:http://stackoverflow.com/questions/6451304/django-simple-custom-template-tag-example
我的demo:
# -*- coding:utf-8 -*-
from django import template register = template.Library()
@register.simple_tag
def one_of(target, *matchlist):
return target in matchlist
动机:django模板中in关键字的实现
碰到的问题:自定义的tag模块无法加载,解决方案参考:http://stackoverflow.com/questions/5493776/django-current-tags-is-not-a-valid-tag-library
即:
1. 检查installed_app是否有这个模块
2. 检查有没有语法错误。 通过python manage.py shell 导入相关的函数(one_of),并执行。
3. 检查该模块的是否在tag实际被引用的模块前面(installed_app里面)。我的问题就卡这里。
4. 其他, 删掉pyc文件、重启服务等等。
使用:xxx.html
{% load my_tags %}
{% one_of 'taget', 'aaa','bbb','ccc','ddd', 'target' as is_in %}
{% if is_in %}
xxxx
{% endif %}
django tag的更多相关文章
- 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...
- Django 文章标签功能
使用第三方框架django-taggit为模型添加标签功能,此模块是一个可复用的应用 首先安装 https://github.com/alex/django-taggit 这是项目主页 pip ins ...
- Django QuerySet 进阶
QuerySet 进阶 阅读本文你可以学习到什么 1. 查看 Django queryset 执行的 SQL(1部分) 2. 获得的查询结果直接以类似list方式展示(2,3 部分) 3. 如何在dj ...
- Hive LLAP
body { margin: 0 auto; font: 13px / 1 Helvetica, Arial, sans-serif; color: rgba(68, 68, 68, 1); padd ...
- Kafka 消费组消费者分配策略
body { margin: 0 auto; font: 13px / 1 Helvetica, Arial, sans-serif; color: rgba(68, 68, 68, 1); padd ...
- Flink SQL结合Kafka、Elasticsearch、Kibana实时分析电商用户行为
body { margin: 0 auto; font: 13px / 1 Helvetica, Arial, sans-serif; color: rgba(68, 68, 68, 1); padd ...
- Hadoop源码:namenode格式化和启动过程实现
body { margin: 0 auto; font: 13px / 1 Helvetica, Arial, sans-serif; color: rgba(68, 68, 68, 1); padd ...
- Hadoop hdfs副本存储和纠删码(Erasure Coding)存储优缺点
body { margin: 0 auto; font: 13px / 1 Helvetica, Arial, sans-serif; color: rgba(68, 68, 68, 1); padd ...
- Java程序中的代理作用和应用场景及实现
body { margin: 0 auto; font: 13px / 1 Helvetica, Arial, sans-serif; color: rgba(68, 68, 68, 1); padd ...
随机推荐
- Android开发之import org.apache.http
在build.gradle(app)中添加一下依赖: android { useLibrary 'org.apache.http.legacy' } dependencies { compile 'o ...
- WinHttp
using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System. ...
- 输入流和字符串互转,InputStream2String,String2InputStream
输入流转字符串 public static String InputStream2String(InputStream in) { InputStreamReader reader = null; t ...
- Web App 压力测试
建议您可以在本地压测来进行评估 具体的压测方法请参考下面的链接:https://www.visualstudio.com/zh-cn/docs/test/performance-testing/run ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'dd' in 'where clause'
今天在使用mysql数据库查找数据的时候报错,错误信息如下: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown co ...
- OAuth2.0相关知识
自己总结的可能有误差. 大致分为6个步骤: 1.注册相关应用,获取client_id,client_secret.2.第三方请求用户授权.用户点击按钮同意授权后,授权服务器将生成一个用户凭证(code ...
- 查找(四)-------基于B树的查找和所谓的B树
关于B树,不想写太多了,因为花在基于树的查找上的时间已经特么有点多了,就简单写写算了,如果以后有需要,或者有时间,可以再深入写写 首先说一下,为什么要有B树,以及B树是什么,很多数据结构和算法的书上来 ...
- UVA1625Color Lenth(DP+LCS变形 未AC)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/C 紫书P276 res[i][j]表示第一个序列移动i个,第 ...
- Python_猜大小
# 需要在python3上执行 import random def game (capital = 1000): point1 = random.randrange(1,7) point2 = ran ...
- Dell R730 配置完RAID后装系统找不到硬盘。
1. 各硬盘只是灯都正常.硬件无故障. 2. 8个600G硬盘做的RAID0和RAID5后都在装系统选盘处找不到硬盘.(注意: 第一次做raid 时,没有进行初始化init.后补做也无效,一直复现这个 ...