Django image loading: IOErrno2 Couldn't find path - and yet it stores the image there anyway?
I have an issue where the local version of django handles image uploads as expected, but my server is down. Note. I am using a Django container at MediaTemple.net (network server).
Here is my code.
def view_settings(request):
<snip>
if request.POST:
success_msgs = ()
mForm = MainProfileForm(request.POST, request.FILES, instance = mProfile)
pForm = ChangePasswordForm(request.POST)
eForm = ChangeEmailForm(request.POST)
if mForm.is_valid():
m = mForm.save(commit = False)
if mForm.cleaned_data['avatar']:
m.avatar = upload_photo(request.FILES['avatar'], settings.AVATAR_SAVE_LOCATION)
m.save()
success_msgs += ('profile pictured updated',)
<snip>
def upload_photo(data,saveLocation):
savePath = os.path.join(settings.MEDIA_ROOT, saveLocation, data.name)
destination = open(savePath, 'wb+')
for chunk in data.chunks():
destination.write(chunk)
destination.close()
return os.path.join(saveLocation, data.name)
Here's where it gets awkward and I was hoping someone could shed some light on this error because either a) it's the wrong error code or b) something happens to the file before it's fully processed. Recall that the file was actually uploaded to the server in the intended directory - and yet this err msg continues to persist.
IOError at / user / settings
[Errno 2] No such file or directory: and '/home/user66666/domains/example.com/html/media/images/avatars/DSC03852.JPG
Environment:
Request Method: POST Request URL:
http://111.111.111.111:2011/user/settings
Django Version: 1.0.2 final Python
Version: 2.4.4 Installed applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites', 'ctrlme',
'usertools', 'easy_thumbnails']
Installed middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback: File "/home/user6666/containers/django/leonidas/usertools/views.py" in view_settings
m.avatar = upload_photo (request.FILES ['avatar'], settings.AVATAR_SAVE_LOCATION) File "/home/user666666/containers/django/leonidas/usertools/functions.py" in upload_photo
destination = open (savePath, 'wb +')
a source to share
No one has answered this question yet
Check out similar questions: