Django: 'current_tags' is not a valid tag library

前端 未结 17 2779
悲&欢浪女
悲&欢浪女 2020-12-23 18:41

I have a small Django project I received from a friend. The code works perfectly on his system. However, on my system I get the following error message when running the serv

17条回答
  •  無奈伤痛
    2020-12-23 19:08

    For others facing this . Suppose your App name is MyApp and your tag folder name is templatetags then in settings.py you should have :

    INSTALLED_APPS = [
    'MyApp',
    'MyApp.templatetags'
    ]
    

    Both your django app and your tag folder which is under your app package are needed there.

    -> MyApp
        ---> models.py
        ---> views.py
        ---> templatetags
          -----> __init__.py
          -----> app_filters.py
    

    And in your template file :

    {% load app_filters %}
    

    Also app_filters.py be like :

    # coding=utf-8
    from django import template
    
    register = template.Library()
    
    
    @register.filter(name='get_item')
    def get_item(dictionary, key):
        return dictionary.get(key)
    

    check all above steps and you may find the issue.

提交回复
热议问题