Yep I just found the thread about the enctype and indeed it was this
and not my comp catching fire!!! Many thanks :)

On Feb 12, 2:48 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Thu, Feb 12, 2009 at 9:38 AM, Karen Tracey <kmtra...@gmail.com> wrote:
> > On Thu, Feb 12, 2009 at 8:02 AM, huw_at1 <huwdjo...@gmail.com> wrote:
>
> >> Hi all,
>
> >> I am trying to write a simple app that allows a user to select a file
> >> (via the browse button) from which data can be read in and parsed. I
> >> have read several examples but none seem to do exactly what I want. I
> >> have built a form and so am trying to use forms.FileField(). I can add
> >> this field no problem to my form. However I am not sure I understand
> >> how I am supposed to pull the data contained within the file from
> >> within my views. I tried:
>
> >> ....
> >> file = forms.FileField()
>
> >> ....
>
> >> if request.FILES:
> >>   filename = request.FILES['file']
>
> >>   ...
>
> >> However I cant seem to get this to work. Does anyone have any good
> >> tutorials or can offer any suggestions?
>
> > Can't get it to work means what, exactly?  Your get an error message?  Your
> > filename variable winds up being set to to something you aren't expecting?
> > Your computer catches fire?
>
> > This page:
>
> >http://docs.djangoproject.com/en/dev/topics/http/file-uploads/
>
> > discusses handling uploaded files in some detail.  As described there,
> > request.FILES['file'] will be an UploadedFile object, so your assignment of
> > it to a variable named 'filename' rather sounds like you have misunderstood
> > something there, since request.FILES['file'] will be more than the file's
> > name, it will be an object with methods and attributes that (as detailed on
> > that page) that let you access the uploaded file's name, size, and data
> > (either in chunks or in one piece).  There's an example handle_uploaded_file
> > function that iterates through the data chunks and does something with
> > them.  Obviously it's not going to do exactly what you want to do with your
> > file data, but that page lays out a whole working structure and would seem
> > to be a good starting point for you to use in developing your specific
> > file-handling code.
>
> > Karen
>
> Remember to set the enctype on your form, this is something a lot of people
> forget.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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