Hi, I have a form class which looks like the below:- > > class UserCreateForm(wtf.Form): > > name=wtf.TextField('Name') > > email=wtf.TextField('Email') > > country=wtf.TextField('Country') > > image=wtf.FileField(u'Upload Image') > > Now after the form is submitted , I am trying to get the file using > file=request.files['image'] but it does not work . I even tried > filename=form.image.file.filename but it says FileField does not have an attribute file Can someone please point me out to where I might be going wrong! >
I solved it.. was an error on my part! On Sat, Oct 30, 2010 at 9:36 AM, alice ni <alice.ni19@gmail.com> wrote: > Hi, I have a form class which looks like the below:- >> >> class UserCreateForm(wtf.Form): >> >> name=wtf.TextField('Name') >> >> email=wtf.TextField('Email') >> >> country=wtf.TextField('Country') >> >> image=wtf.FileField(u'Upload Image') >> >> Now after the form is submitted , I am trying to get the file using > >> file=request.files['image'] > > > > but it does not work . I even tried > >> filename=form.image.file.filename > > but it says FileField does not have an attribute file > > Can someone please point me out to where I might be going wrong! > >> > >
Care to share solution? Just for completeness sake. -- Thadeus On Sat, Oct 30, 2010 at 12:08 AM, alice ni <alice.ni19@gmail.com> wrote: > I solved it.. was an error on my part! > > > On Sat, Oct 30, 2010 at 9:36 AM, alice ni <alice.ni19@gmail.com> wrote: > >> Hi, I have a form class which looks like the below:- >>> >>> class UserCreateForm(wtf.Form): >>> >>> name=wtf.TextField('Name') >>> >>> email=wtf.TextField('Email') >>> >>> country=wtf.TextField('Country') >>> >>> image=wtf.FileField(u'Upload Image') >>> >>> Now after the form is submitted , I am trying to get the file using >> >>> file=request.files['image'] >> >> >> >> but it does not work . I even tried >> >>> filename=form.image.file.filename >> >> but it says FileField does not have an attribute file >> >> Can someone please point me out to where I might be going wrong! >> >>> >> >> >
Well.. missed out enctype in the form! .. :-) On Sat, Oct 30, 2010 at 12:10 PM, Thadeus Burgess <thadeusb@thadeusb.com>wrote: > Care to share solution? Just for completeness sake. > > -- > Thadeus > > > > > > On Sat, Oct 30, 2010 at 12:08 AM, alice ni <alice.ni19@gmail.com> wrote: > >> I solved it.. was an error on my part! >> >> >> On Sat, Oct 30, 2010 at 9:36 AM, alice ni <alice.ni19@gmail.com> wrote: >> >>> Hi, I have a form class which looks like the below:- >>>> >>>> class UserCreateForm(wtf.Form): >>>> >>>> name=wtf.TextField('Name') >>>> >>>> email=wtf.TextField('Email') >>>> >>>> country=wtf.TextField('Country') >>>> >>>> image=wtf.FileField(u'Upload Image') >>>> >>>> Now after the form is submitted , I am trying to get the file using >>> >>>> file=request.files['image'] >>> >>> >>> >>> but it does not work . I even tried >>> >>>> filename=form.image.file.filename >>> >>> but it says FileField does not have an attribute file >>> >>> Can someone please point me out to where I might be going wrong! >>> >>>> >>> >>> >> >
I'm considering adding file-based validators as well - for example, the required validator doesn't work on file fields, as the request.form field is empty, even if the request.files field is not. This might be used with Flask-Uploads so it's possible to check specific file types such as images as well. On 30 October 2010 10:49, alice ni <alice.ni19@gmail.com> wrote: > Well.. missed out enctype in the form! .. :-) > > On Sat, Oct 30, 2010 at 12:10 PM, Thadeus Burgess <thadeusb@thadeusb.com> > wrote: >> >> Care to share solution? Just for completeness sake. >> >> -- >> Thadeus >> >> >> >> >> On Sat, Oct 30, 2010 at 12:08 AM, alice ni <alice.ni19@gmail.com> wrote: >>> >>> I solved it.. was an error on my part! >>> >>> On Sat, Oct 30, 2010 at 9:36 AM, alice ni <alice.ni19@gmail.com> wrote: >>>> >>>> Hi, I have a form class which looks like the below:- >>>>>> >>>>>> class UserCreateForm(wtf.Form): >>>>>> >>>>>> name=wtf.TextField('Name') >>>>>> >>>>>> email=wtf.TextField('Email') >>>>>> >>>>>> country=wtf.TextField('Country') >>>>>> >>>>>> image=wtf.FileField(u'Upload Image') >>>> >>>> Now after the form is submitted , I am trying to get the file using >>>>> >>>>> file=request.files['image'] >>>>> >>>>> >>>> >>>> but it does not work . I even tried >>>>> >>>>> filename=form.image.file.filename >>>> >>>> but it says FileField does not have an attribute file >>>> Can someone please point me out to where I might be going wrong! >>>>> >>>>> >> > >
Hi danjac ! I have done something like that ..You can read the mail concerning this at the below link for that:- http://groups.google.com/group/wtforms/browse_thread/thread/bb42b8c1763c5141 On Mon, Nov 1, 2010 at 5:17 PM, danjac354@gmail.com <danjac354@gmail.com>wrote: > I'm considering adding file-based validators as well - for example, > the required validator doesn't work on file fields, as the > request.form field is empty, even if the request.files field is not. > > This might be used with Flask-Uploads so it's possible to check > specific file types such as images as well. > > On 30 October 2010 10:49, alice ni <alice.ni19@gmail.com> wrote: > > Well.. missed out enctype in the form! .. :-) > > > > On Sat, Oct 30, 2010 at 12:10 PM, Thadeus Burgess <thadeusb@thadeusb.com > > > > wrote: > >> > >> Care to share solution? Just for completeness sake. > >> > >> -- > >> Thadeus > >> > >> > >> > >> > >> On Sat, Oct 30, 2010 at 12:08 AM, alice ni <alice.ni19@gmail.com> > wrote: > >>> > >>> I solved it.. was an error on my part! > >>> > >>> On Sat, Oct 30, 2010 at 9:36 AM, alice ni <alice.ni19@gmail.com> > wrote: > >>>> > >>>> Hi, I have a form class which looks like the below:- > >>>>>> > >>>>>> class UserCreateForm(wtf.Form): > >>>>>> > >>>>>> name=wtf.TextField('Name') > >>>>>> > >>>>>> email=wtf.TextField('Email') > >>>>>> > >>>>>> country=wtf.TextField('Country') > >>>>>> > >>>>>> image=wtf.FileField(u'Upload Image') > >>>> > >>>> Now after the form is submitted , I am trying to get the file using > >>>>> > >>>>> file=request.files['image'] > >>>>> > >>>>> > >>>> > >>>> but it does not work . I even tried > >>>>> > >>>>> filename=form.image.file.filename > >>>> > >>>> but it says FileField does not have an attribute file > >>>> Can someone please point me out to where I might be going wrong! > >>>>> > >>>>> > >> > > > > >