ImportError:无法从Django Admin Pi导入name\u映像访问

2024-05-13 01:20:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经为这个错误挣扎了两天,尝试了堆栈溢出的所有答案,但没有运气。我有一个使用Django图像场的简单模型

class Author(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.EmailField()
    url = models.URLField(blank=True, null=True)
    short_bio = models.TextField(max_length=200, blank=True, null=True)
    long_bio = models.TextField(max_length=5000, blank=True, null=True)
    role = models.ManyToManyField(AuthorRole)
    facebook_link = models.URLField(blank=True, null=True)
    linkedin_link = models.URLField(blank=True, null=True)
    twitter_link = models.URLField(blank=True, null=True)
    gplus_link = models.URLField(blank=True, null=True)
    thumbnail = models.ImageField(upload_to='images/',     default='images/user_default.jpg')

在生产服务器中,当我从管理访问模型并选择一个映像并尝试保存时,它抛出以下错误。我安装和卸载枕头好几次。尝试了不同版本的django和枕头。顺便说一句,它在当地环境下工作良好。在

^{pr2}$

我可以从管理.py壳牌。看来pythonpath配置正确。enter image description here

在我的虚拟现实里我可以看到_成像.cpython-34m.so文件,但没有 _成像.py文件。enter image description here

我的服务器托管在linode。是Ubuntu 14.04。我用的是Apache2。Python 3.4.3。Django 1.10枕头3.3.0。你的热心帮助是非常值得赞赏的。这个错误困扰了我很长时间。在

1:http://i.stack.imgur.com/nH8O3.jpg2:http://i.stack.imgur.com/Vpdoe.jpg


Tags: djangoname模型truemodels错误linknull
1条回答
网友
1楼 · 发布于 2024-05-13 01:20:23

好吧,我终于得到了答案。这跟枕头没关系。我给了public对保存图像的“media”文件夹的写权限,它突然解决了这个问题。我不确定这是否是一个安全漏洞,但它解决了错误。在

我是怎么找到的:
我决定改变图像.py文件来自PIL。在

  try:
    # If the _imaging C module is not present, Pillow will not load.
    # Note that other modules should not refer to _imaging directly;
    # import Image and use the Image.core variable instead.
    # Also note that Image.core is not a publicly documented interface,
    # and should be considered private and subject to change.
    from PIL import _imaging as core
    if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
        raise ImportError("The _imaging extension was built for another "
                          " version of Pillow or PIL")

except ImportError as v:
    core = _imaging_not_installed()
    # Explanations for ways that we know we might have an import error
    if str(v).startswith("Module use of python"):
        # The _imaging C module is present, but not compiled for
        # the right version (windows only).  Print a warning, if
        # possible.
        warnings.warn(
            "The _imaging extension was built for another version "
            "of Python.",
            RuntimeWarning
            )
    elif str(v).startswith("The _imaging extension"):
        warnings.warn(str(v), RuntimeWarning)
    elif "Symbol not found: _PyUnicodeUCS2_" in str(v):
        # should match _PyUnicodeUCS2_FromString and
        # _PyUnicodeUCS2_AsLatin1String
        warnings.warn(
            "The _imaging extension was built for Python with UCS2 support; "
            "recompile Pillow or build Python  without-wide-unicode. ",
            RuntimeWarning
            )
    elif "Symbol not found: _PyUnicodeUCS4_" in str(v):
        # should match _PyUnicodeUCS4_FromString and
        # _PyUnicodeUCS4_AsLatin1String
        warnings.warn(
            "The _imaging extension was built for Python with UCS4 support; "
            "recompile Pillow or build Python  with-wide-unicode. ",
            RuntimeWarning
            )
    # Fail here anyway. Don't let people run with a mostly broken Pillow.
    # see docs/porting.rst
    raise

except块正在检查一些条件,最后一行再次引发导入错误。我注释掉了raise,结果显示了权限错误。 我不知道为什么它在地球上显示进口错误,而问题是许可。我希望pillow的作者能够看到这个问题,并尝试生成相关的错误消息,而问题并不是真正的导入错误而是权限错误。在

相关问题 更多 >