本文介绍了需要解决sor-thumbnail错误的帮助:“'thumbnail'不是有效的标签库:"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力解决此问题,我已经做了所有尝试,但我没有想法.

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

我一直看到此错误:异常值:'thumbnail'不是有效的标记库:无法从django.templatetags.thumbnail加载模板库,没有名为sorl.thumbnail.main的模块

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存在.

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

这就是我要做的设置

  1. 下载了最新的sorl-thumbnail,并将其位置添加到.bash_profile中的python路径

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

在INSTALLED_APPS中包含了"sorl.thumbnail"(在Django的settings.py中)

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

在Django模板中使用了{%load thumbnail%}标签

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

很明显,未正确安装sorl-thumbnail,但是我能够从python shell和django shell导入缩略图(当我使用{%load thumbnail%}时会出现此错误).另外,相关文件中没有错别字(我已经检查了很多次).

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).

推荐答案

我敢猜测这是一个$ PYTHONPATH问题."thumbnail"目录是否在路径上,而不是在"sorl"目录下?我怀疑这是问题所在,因为您不想在Python解释器上键入导入缩略图".您应该改为键入"import sorl.thumbnail".

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.

您还希望确保当前的工作目录不是../sorl/根目录(即,不要从sorl文件夹运行python).这将使您可以直接导入缩略图.

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.

您应该从python解释器中检查完整的Python路径(该路径将超过$ PYTHONPATH),以验证您的包位置:

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

进一步了解 Python导入

这篇关于需要解决sor-thumbnail错误的帮助:“'thumbnail'不是有效的标签库:"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:37