image KeyError
hi there , so i am not sure if i am doing this the right way, but im successfully able to upload files(images) and store them in my defined folder and the link in my mysql database.
the error comes when i try to return the image with the HTTP RESPONSE were i get a image keyError.. i am not sure wht i am doing wrong..
here is my code:
def handle_uploaded_file(f,u):
profile=u.get_profile()
profile.avatar=f.name
destination = open('images/users/'+f.name, 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()
profile.save()
def upload_file(request,user_id):
u = get_object_or_404(User, pk=user_id)
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['file'],u)
uploadedImage = form.cleaned_data['image']
return HttpResponse(uploadedImage.content,mimetype="image/jpeg")
else:
form = UploadFileForm()
c = {'form': form,'user' : u}
c.update(csrf(request))
return render_to_response('accounts/upload.html', c)
<form enctype="multipart/form-data" method="post" action="/accounts/{{ user.id }}/upload/">
{% csrf_token %}
<table>
{{form.as_table}}
</table>
<input type="submit" value="Submit" id="Save"/>
</form>
thanks in advance
-- You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Da_0Y9V6oyAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home