django custom filter invalid error

0 0 python2.7 python-django
l梁上君子
l梁上君子

声望值:141 0人

2019-03-06 15:27:27 提问

关注 0关注

收藏 0收藏, 147浏览

我自定义了一个filer但加载的时候报错了

目录结构
templates/

index.html

ticket_track/

models.py
views.py
templatetags/
    __init__.py
    my_filter.py
    

ticket_request_system/

settings.py
    

index.html

{% extends "base.html" %}
{% load my_filter %}

{{ ticket.params|my_tag:"domain" }}

my_filter.py

#!/usr/bin/env python
#coding:utf-8

from django import template
import json

register = template.Library()

@register.filter
def str_dic(format_string,args):
    return json.loads(format_string)[args]

register.tag('my_tag', str_dic) 

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ticket_track'
]

报错信息如下:

TemplateSyntaxError at /tickets/working

Invalid filter: 'my_tag'

Request Method:     GET
Request URL:     http://ticket.web.isd.com/tickets/working
Django Version:     1.11.1
Exception Type:     TemplateSyntaxError
Exception Value:     

Invalid filter: 'my_tag'

Exception Location:     /usr/local/lib/python2.7/site-packages/Django-1.11.1-py2.7.egg/django/template/base.py in parse, line 515
Python Executable:     /usr/local/bin/python2.7
Python Version:     2.7.12
Python Path:     

['/data/release/ticket_request_system_test_env/code_alt',
 '/usr/local/lib/python27.zip',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/usr/local/lib/python2.7/lib-old',
 '/usr/local/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/setuptools-25.2.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/requests-2.14.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/Django-1.11.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pytz-2017.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/enum34-1.1.6-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/redis-2.10.5-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/supervisor-3.3.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/meld3-1.0.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/ChatterBot-0.6.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/SQLAlchemy-1.1.10-py2.7-linux-x86_64.egg',
 '/usr/local/lib/python2.7/site-packages/python_twitter-3.3-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pymongo-3.4.0-py2.7-linux-x86_64.egg',
 '/usr/local/lib/python2.7/site-packages/nltk-3.2.4-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/jsondatabase-0.1.7-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/chatterbot_corpus-0.0.1-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/requests_oauthlib-0.8.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/future-0.16.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/oauthlib-2.0.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/db.py-0.5.3-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pybars3-0.9.3-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pandas-0.20.2-py2.7-linux-x86_64.egg',
 '/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg',
 '/data/release/ticket_request_system_test_env/code_alt']

Server time:     Fri, 15 Dec 2017 11:15:20 +0800

我是按照django的官方文档配置的..这个错误为啥有,麻烦大神帮忙看看

clipboard.png

请先 登录 后评论

0个回答

注册新账号

悬赏追问
10
  • 10
  • 20
  • 50
  • 100
  • 200
  • 输入数值
发布追问