Django: 'current_tags' is not a valid tag library

前端 未结 17 2690
悲&欢浪女
悲&欢浪女 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:18

    In my case I have created library instance using tag variable instead of register variable

    tag = template.Library()
    

    But it should be

    register = template.Library()
    

    To be a valid tag library, the module must contain a module-level variable named register that is a template.Library instance, in which all the tags and filters are registered

    0 讨论(0)
  • 2020-12-23 19:19

    After you have created the template tag and it should be within the 'templatetags' package within an app installed in the settings.INSTALLED_APPS, make sure you restart your dev-server.

    0 讨论(0)
  • 2020-12-23 19:21

    All of the advice listed here didn't help me. So in my specific case the problem was that the templatetag had to be loaded from a third-party app, and I manually copied source folder with that app into src folder in my virtualenv. Then I ran python setup.py install inside that folder. After that django could not load this module.

    Then I removed the source and installed folder of this app and installed it using pip install -r requirements.txt after adding a relevant line into requirements.txt file. It was downloaded into the src folder, installed and everything began working properly. Hope this helps someone.

    0 讨论(0)
  • 2020-12-23 19:23

    I had this problem and fixed it by adding a blank __init__.py file in my appname/templatetags/ directory.

    0 讨论(0)
  • 2020-12-23 19:29

    Possibilities are many:

    1. You haven't reset your dev server.
    2. You have dependency loop in templatetag file.
    3. You misspelled something (directory, folder, template name in 'load', etc.).
    4. You forgot about adding the app to INSTALLED_APPS.
    0 讨论(0)
提交回复
热议问题