I have gotten it to work finally.  In my code above
newform['data_file'] actually outputs html code, not a dictionary.
That was the reason why it was "unsubscriptable".

So instead of saying newform['data_file']['filename'], I requested
form_data['data_file']['filename'].  But then django complained that
form_data['data_file'] can only be indexed via integers.

It turns out that for strange reason the multi-valued dictionary in
request.FILES, when updated into the form_data dictionary, transforms
into a list.  I'm not sure why this is.  When I requested the
dictionary form_data['data_file'] it gave me a list like this:

[ {'content': somecontent, 'filename': somename } ]

So when I tried to say form_data['data_file']['filename'] it again
complained that the list can only be indexed via integers.  I guess
the correct way to get the filename in this case would be to say
form_data['data_file'][0]['filename'].  But that is totally weird and
counterintuitive.

My final solution was to directly use request.FILES['data_file']
['filename'] and that solved the problem.  But I am still very
confused as to why when I update request.FILES to form_data, it would
transform the multi-valued dictionary into a list?

Any clue?


On May 12, 8:21 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 5/13/07, jonathan_ou <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am trying to upload a file using the newforms library.  So far from
> > reading other posts and googling around it appears I have to copy the
> > request.POST dictionary and update it with request.FILES.  Then I
> > would do a "model.save_<fieldname>_file(<filename>, <content>)" to
> > actually save the file.
> ...
> > So there is something Django doesn't like about this line.  Can
> > someone tell me what I'm doing wrong?
>
> Unfortunately, File uploading fields don't yet fully work under
> newforms. This is something I'm hoping to address in the near future.
>
> Yours,
> Russ Magee %-)


--~--~---------~--~----~------------~-------~--~----~
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