Correction: request.FILES does exist -- it just wasn't getting printed
out with "print request".  An explicit "print request.FILES" did the
trick.

However, my question still stands: is form.save(commit=False) supposed
to be writing the file out to disk?  Is this the newforms way of
handling uploads, and therefore is checking for request.FILES and
writing the file out ourselves passé?

On May 8, 3:43 pm, Beals <[EMAIL PROTECTED]> wrote:
> A while back, I looked for code snippets for uploading files.  Almost
> every site I found contained something like the following:
>
> if 'file' in request.FILES:
>     file = request.FILES['file']
>     filename = file['filename']
>     fd = open('%s/%s' % (MEDIA_ROOT, filename), 'wb')
>     fd.write(file['content'])
>     fd.close
> else:
>     print "No file attached."
>
> This seemed to work -- files were uploaded and the pointers from the
> model worked fine, so I never thought to look at the logs... until
> today, and I noticed that even though the uploads were working
> properly, the "No file attached" message kept showing up.  Drilling
> in, I found that FILES wasn't even in the request object!  Yet the
> file was still written to disk... weird.
>
> So I started putting breakpoints in to figure out where in my view the
> file was getting written out.  The fourth line is the culprit:
>
> if request.method == 'POST':
>     form = FooForm(request.POST, request.FILES)
>     if form.is_valid():
>         new_artifact = form.save(commit=False)
>         *BREAKPOINT*
>
> So how/why is form.save(commit=False) writing the file out to disk??
> Is this expected behavior for ModelForms?  (NOTE: in case it matters,
> I'm using the built-in Django webserver.)
>
> -Aaron
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to