I was reading https://docs.djangoproject.com/en/1.3/topics/http/file-uploads/,
and I got a little confused when looking at the handle_uploaded_file
function.

def handle_uploaded_file(f):
    destination = open('some/file/name.txt', 'wb+')
    for chunk in f.chunks():
        destination.write(chunk)
    destination.close()

in the destination line, it refers to a specific text file. I don't
understand how this function is universal to all files if this is the
case. Shouldn't the destination be a simple path? like open('some/
file/', 'wb+)? Also, if I want the files to be organized in such a way
that each user gets their files uploaded to their own folder, where
would this part of the code go?
I was thinking the following:

def handle_uploaded_file(f, user):
    destination = open("%s/documents/" %user, 'wb+')
    for chunk in f.chunks():
        destination.write(chunk)
    destination.close()

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to