Django: "current_tags" is not a valid tag library

I have a small Django project that I received from a friend. The code works fine on his system. However, on my system, I get the following error message when starting the server:

TemplateSyntaxError in /

'current_tags' is not a valid tag library: the current_tags template library was not found, tried django.templatetags.current_tags

The problem is the line in the html file:

{% load current_tags %} 

This exact code works in his system without errors. What could it be?

+74
python django portability
Mar 30 '11 at 23:45
source share
17 answers

I would suggest the following:

  • (Most likely) You have not installed one of the dependencies of your tag library. Check the import inside the current_tags.py module.

  • Verify that the application containing the tag library is registered in settings.py under INSTALLED_APPS .

  • Make sure you import the tag library successfully.

     python manage.py shell >>> from app.templatetags import current_tags 

    This leads to the fact that the following link recommends that the error itself, as a rule, misleads you as to where it is looking for a template. It silently ignores import errors, which means that current_tags.py may have a syntax error or some other reason why it raises ImportError.

If all else fails, check this link: http://www.b-list.org/weblog/2007/dec/04/magic-tags/

+80
Mar 31 '11 at 1:27
source share

I had this problem and fixed it by adding an empty __init__.py file to the appname / templatetags / directory.

+74
Sep 03 '11 at 5:23
source share

There are many possibilities:

  • You do not reset your dev server .
  • You have a dependency loop in the templatetag file.
  • something is wrong (directory, folder, template name in 'load', etc.).
  • You forgot to add the application to INSTALLED_APPS .
+62
Oct 09 '12 at 18:21
source share

Restarting the server solved the problem for me. They should have mentioned this in the documentation.

+10
Jan 08 '17 at 2:01 on
source share

I was getting the same error, but for a different reason, so I will tell you (in case someone else is facing the same problem).

I had everything right, but I had my own tag inside a folder called template_tags , and after a long search I found out that it should be templatetags , and now it works. So check the folder name for exactly templatetags .

+6
Jun 19 '13 at 14:15
source share

Suppose you have the following structure:

- Application_Name

------- templatetags

-------------- INIT .py

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

------- INIT .py

------- settings.py

- manage.py

You must verify the following:

  • your application inside which your "templatetags" is resident is actually set to INSTALLED_APPS in settings.py (for example, "Application_Name")

  • the tag module itself, which exists inside "templatetags", is already set to INSTALLED_APP in settings.py (for example, "ApplicationName.templatetags.tempaltes_extras")

  • make sure you have init .py "in the templatetags directory

  • you need to restart the server

  • In some cases, you need to delete all generated * .pyc, if they do not work, then try again

+6
Feb 05 '14 at 20:44
source share

"custom tags" is not a valid tag library error, most often because custom tags are not loaded into the application.

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

 touch __init__.py 
+5
Feb 19 '15 at 15:51
source share

Please make sure your templatetags folder is initialized with python, if in doubt, just take bakup from all the files,

Delete all files, Inside the templatetags folder, create an init .py file, then restart the server,

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

This works for me ...

+3
Feb 28 '15 at 8:15
source share

For me, it was a mistake placing quotes around the library name in the load tag.

INCORRECT: {% load 'library_name' %}

CORRECT: {% load library_name %}

See also other answers. I solved a couple of these problems before landing here.

+3
Jul 20 '16 at 12:00
source share

For others facing this. Suppose your application name is MyApp , and your tag name is templatetags , and then in settings.py should be:

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

You need both your django application and your tag folder located under your application.

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

And in your template file:

 {% load app_filters %} 

Also app_filters.py will look 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 the above steps and you may find the problem.

+3
Jun 29 '17 at 20:08
source share

Verify that the load statement is correct. This should be a file name, not an application name. For example, if you have this application:

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

Then you should put this in your template:

 {% load foobarfilename %} 

Of course, you should check other answers as well.

+2
May 13 '16 at 12:31
source share

After creating the template tag, it should be in the templatetags package in the application installed in settings.INSTALLED_APPS, make sure you restart your dev server.

+2
Jun 25 '16 at 16:17
source share

Maybe someone finds this useful: somehow I called the directory 'templatetags ' instead of 'templatetags' , that is, with a space at the end. Took a watch to finally understand.

+1
Oct 21 '16 at 19:09
source share

All the tips given here did not help me. Therefore, in my particular case, the problem was that templatetag had to be downloaded from a third-party application, and I manually copied the source folder with this application to the src folder in my virtualenv. Then I ran python setup.py install inside this folder. After that, django was unable to load this module.

Then I deleted the source and installed folder of this application and installed it using pip install -r requirements.txt after adding the corresponding line to the requirements.txt file. It was downloaded to the src folder installed, and everything started working properly. Hope this helps someone.

0
Nov 05
source share

In my case, I created an instance of the library using the tag variable instead of the register variable

 tag = template.Library() 

But it must be

 register = template.Library() 

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

0
Jul 18 '17 at 17:45
source share

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

I had to change to {% filename %}

0
Jul 17 '19 at 10:43
source share

In my case it was - I use

 @register.inclusion_tag('template-to-use.html') 

I forgot to create this template, and it immediately started working. I know that the answers above are more related to most questions, but I hope someone finds this useful. It should have got me:

 Template does not exist 

but it is not, and it worked.

0
Jul 17 '19 at 16:55
source share



All Articles