2
votes

I've been pulling my hair out trying to solve this problem and I've tried everything and I have no ideas left.

I keep seeing this error: Exception Value: 'thumbnail' is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module named sorl.thumbnail.main

$DJANGO_PACKAGES/sorl/thumbnail/main.py DOES exist.

Here's what I did to setup,

  1. downloaded latest sorl-thumbnail and added its location to the python path in .bash_profile

  2. included 'sorl.thumbnail' in INSTALLED_APPS (in django's settings.py)

  3. used the {% load thumbnail %} tag in a django template

It would seem obvious sorl-thumbnail is not installed correctly, but I'm able to import thumbnail from the python shell and the django shell (when I use {% load thumbnail %} it brings this error). Also, there are no typos in related files (I've checked many many times).

3

3 Answers

2
votes

I would venture to guess this is a $PYTHONPATH issue. Is it possible that the "thumbnail" directory is on the path and not "sorl"? I suspect this is the issue because you do not want to be able to type "import thumbnail" on the Python interpreter. You should instead have to type "import sorl.thumbnail".

Another thing to check is to print the module name after importing:

>>> import thumbnail
>>> print thumbnail

This will display the filesystem location where the module was found, in case it's loading another copy from somewhere you do not expect.

You also want to make sure your current working directory is not the root ../sorl/ location (ie. don't run python from the sorl folder). This will allow you to import thumbnail straight-away.

You should check your full Python path (it will be more than $PYTHONPATH) from within the python interpreter to verify your package locations:

>>> import sys
>>> print sys.path

It might also be helpful to learn more about Python importing

0
votes

Problem solved.

When following the django book, it is suggested to create apps within a project directory and to refer to these apps in the INSTALLED APPS statement with a path that begins from the directory containing the project, for example, 'siteproject.books'. I was not able to give django access to apps without appending that directory name to the file path, so, for example, I was not able to simply use 'books', but needed to use 'siteproject.books' in the INSTALLED APPS statement and this was the case with sorl.thumbnail, which needed to be referred to as siteproject.sorl.thumbnail. Other attempts to include 'sorl.thumbnail' would yield a very ugly un-formatted and confusing purple-colored error page (yes, the sorl directory was in $PYTHONPATH, so who knows why these attempts didn't work...).

Unfortunately, Django was yielding the 'undefined tag' error, which is a generalized error that it gives in many situations. It doesn't really mean anything and isn't useful for locating problems.

The problem was solved when I opened the files in the sorl directory and edited the python files. I found import statements that imported objects from the sorl directory and I appended the 'siteproject.*' to those paths and everything began to work.

0
votes

Here's another general tip on the unhelpful 'not a valid tag library' message: for tags that you create, it could be as simple as a syntax error.

Hat tip: 'Rock' on Django-users: http://groups.google.com/group/django-users/browse_thread/thread/d65db3940acf16c3?tvc=2