Pythonanywhere将图像文件保存在一步父目录中,而不是正确的目录中。 *开发服务器运行良好))>

问题描述 投票:0回答:1

我已将自定义字段保存为图像和缩略图。缩略图应保存在'/.../.../targetimage/thumbnails/'文件夹中,完整尺寸的图像应保存在'... / ... / targetimage /'文件夹中。

当我在本地开发服务器上运行customfield文件时,图像将进入正确的目录。但是在pythonanywhere中,原始图像和缩略图图像进入同一目录。我不明白为什么Pythonanywhere以不同的方式起作用。

fields.py

def _add_path_to_thumb(s):
    print('this is path',s)
    fname_list=[]
    parts = s.split(".")
    print('this is parts',parts)
    pathparts=parts[0].split("\\")
    print('this is pathparts', pathparts)
    fname_list.append(pathparts[-1])
    fname_list.append('-thumb')
    fname_list.append('.jpg')
    fname ="".join(fname_list)
    del pathparts[-1]
    pathparts.extend(['thumbnails\\'])
    print('this is pathparts final', pathparts)
    path_prop = "\\".join(pathparts)
    print('this is pathparts final prop', path_prop)
    MEDIA_ROOT_THUMB = os.path.join(MEDIA_ROOT, 'target_image/thumbnails/')
    print('this is media_root_thumb', MEDIA_ROOT_THUMB)
    fullopathusingos = os.path.join(MEDIA_ROOT_THUMB,fname)
    print('this is full path using os ',fullopathusingos )

    fullpath = path_prop+fname
    return fullopathusingos


我已将自定义字段保存为图像和缩略图。缩略图应保存在“ /.../.../targetimage/thumbnails/”文件夹中,完整尺寸的图像应保存在“ ... / ... / targetimage /”文件夹中。当我...

image file path pythonanywhere
1个回答
0
投票

您将在使用\和/作为路径分隔符之间进行切换。在Windows上它将以一种方式运行,在PythonAnywhere上将以另一种方式运行。我怀疑问题的主要原因是在\上拆分,因为在PythonAnywhere上,您将无法获得在\上拆分将其分成目录部分的路径。

© www.soinside.com 2019 - 2024. All rights reserved.