zoukankan      html  css  js  c++  java
  • Django中添加自定义的simple_tag

    Django自定义simple_tag时出错如下:

    TemplateSyntaxError at /app/

    'my_tag' is not a registered tag library. Must be one of:
    admin_list
    admin_modify
    admin_static
    admin_urls
    cache
    i18n
    l10n
    log
    static
    staticfiles
    tz
    xxoo

    解决办法:
      在setting.py文件中添加注红部分
    TEMPLATES = [
    {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': True,
    'OPTIONS': {
    'context_processors': [
    'django.template.context_processors.debug',
    'django.template.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages',
    ],
    'libraries':{
    "你的自定义标签":"app名.templatetags.自定义函数",
    },

    },
    },
    ]

    注意:

    html模板中
    {% load 文件名 %} 对应 templatetags中的 py文件名



    {% 自定义标签 args %} 对应templatetags下py文件中函数


    原文地址:http://blog.51cto.com/zhangrf/2107991


    努力有用的话,还要天才做什么呢?
  • 相关阅读:
    判断
    数的读写
    单词长度
    c语言字符串大小写字母转换
    URL超长问题
    使用Loadrunner录制手机端http请求
    NoSql 数据库理解
    .NET, ASP.NET, ADO.NET, C# 区别
    Browser 对象
    装箱与拆箱
  • 原文地址:https://www.cnblogs.com/crazy-xf/p/9309339.html
Copyright © 2011-2022 走看看