I have made custom field to save image and thumnail. Thumnail should be saved at '/.../.../targetimage/thumbnails/' folder and full sized images should be at '.../.../targetimage/ 'folder.
When I run the customfield file at local development server, the images go into correct directory. But in the pythonanywhere, original and thumbnail images go into same directory. I can not understand why the Pythonanywhere acts in different way.
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
You're switching between using \ and / as path separators. It will behave one way on Windows and another way on PythonAnywhere. I suspect the main cause of the problem is splitting on \ because, on PythonAnywhere, you will not get a path where splitting on \ breaks it into directory parts.