Django: 'current_tags' is not a valid tag library

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

    Please ensure your templatetags folder is initialized with python, if you are in doubt, just take bakup of all files,

    Remove all files, Inside templatetags folder create init.py file only, then restart your server,

    Now your folder is under Python, then do your stuff.

    This works for me...

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

    Make sure the load statement is correct. It should be the name of the file, not the name of the app. For instance, if you have this app:

    appname
    ├── __init__.py
    ├── templatetags
    │   ├── __init__.py
    │   └── foobarfilename.py
    

    Then you should put this in your template:

    {% load foobarfilename %}
    

    Of course, you should check the other answers too.

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

    In my case the problem was, I was using {% load filter_method_name %}

    I had to change to {% filename %}

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

    Restart the server has solved the issue for me. They must have mentioned it in the documentation.

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

    suppose you have the following structure:

    -- Application_Name

    -------templatetags

    --------------init.py

    --------------templates_extras.py

    -------init.py

    -------settings.py

    -- manage.py

    You have to make sure of the following:

    • your application itself inside which your "templatetags" is resident is actually installed in INSTALLED_APPS in settings.py (e.g. "Application_Name")

    • your tag module itself that exists inside "templatetags" is already installed in INSTALLED_APP in settings.py (e.g. "ApplicationName.templatetags.tempaltes_extras")

    • keep sure you have "init.py" under templatetags directory

    • you have to restart the server

    • In some cases you have to remove all generated *.pyc if it did not work then retry again

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

    "custom tags" is not a valid tag library error, more often is occurred because the custom tags are not loaded into the app.

    place an empty init.py inside the same folder where your "custom template tag" is placed and run the below code on the terminal to load the custom template tags

    touch __init__.py
    
    0 讨论(0)
提交回复
热议问题