Need help solving sorl-thumbnail error: "thumbnail" is not a valid tag library:

I am pulling my hair out trying to solve this problem and I have tried everything and I have no ideas.

I see 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 exist.

Here's what I did to set it up,

  • downloaded the latest thumbnail screen and added its path to python path in .bash_profile

  • included "sorl.thumbnail" in INSTALLED_APPS (in django settings.py)

  • used {% load thumbnail%} tag in django template

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

+2


source to share


3 answers


I would venture to guess that this is the $ PYTHONPATH problem. Is it possible that the "thumbnail" folder is on the path and not "sorl"? I suspect this is a problem because you don't want to type "import thumbnail" into the Python interpreter. Instead, you need to enter "import sorl.thumbnail".

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

>>> import thumbnail
>>> print thumbnail

      

The filesystem location where the module was found will be displayed if it loads another copy from somewhere you don't expect.



You also want to make sure that your current working directory is not the root location. / Sorl / (i.e. don't run python from the sorl folder). This will allow you to import the thumbnail immediately.

You have to check your full Python path (it will be greater than $ PYTHONPATH) from the python interpreter to check the location of your package:

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

      

It might also be helpful to know more about Python imports

+2


source


The problem has been resolved.

When executing the django book, it is suggested to create apps in the project directory and reference those apps in the INSTALLED APPS statement with a path that starts with the directory containing the project, for example "siteproject.books", I was unable to give django access to the apps without adding this directory name to file path, so for example I couldn't just use "books", but I needed to use "siteproject.books" in the INSTALLED APPS statement and that was the case with sorl.thumbnail, which needed to be named siteproject. sorl.thumbnail. Other attempts to include "sorl.thumbnail" will result in a very ugly unformatted and confusing purple error page (yes, the sorl directory was in $ PYTHONPATH, so who knows why those attempts didn't work ...).



Unfortunately Django gave an "undefined" error, which is a generic error that it gives in many situations. It doesn't really mean anything and is not useful for finding problems.

The problem was solved when I opened the files in the sorl directory and edited the python files. I found import instructions that imported objects from the sorl directory and I added "siteproject. *" To those paths and everything started working.

0


source


Here's another general tip about the useless "Invalid tag library" message: for generated tags, this can be as simple as a syntax error.

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

0


source







All Articles