Don't put the form.accepts inside the 'if request.vars' block -- it needs to run even on form creation (to generate the hidden formname and formkey fields).
On Saturday, November 19, 2011 12:44:31 PM UTC-5, miroslavgojic wrote: > > Now I have in controller: > def upload(): > form = FORM("Upload > > file:",INPUT(_type='file',_name='myfile'),INPUT(_type='submit',_name='submit',_value='Submit')) > if request.vars: > if form.accepts(request,session): > my_file = request.vars.myfile.file > my_filename = request.vars.myfile.filename > filepath = os.path.join(request.folder, 'uploads') // this > path work - it is absolute path in hard drive > fp =open(filepath.my_filename,'wb') > fp.write(my_file) > fp.close() > return dict(form=form) > > request.vars.myfile -> make return on stored object > request.vars.myfile.file -> make return address of stored object > > I understood what you told me, and logical check on conditions, but > how to put everything in one function. > > the pseudo algorithm in my head is next: > > make def func(): > make form = FORM(...) > check if condition existing > make file = request.vars.myfile.file > make filename = request.vars.myfile.filename > make filepath = os.path.join(...) > make write file to filepath filename > go to page and show empty form - wait for new file > else: > just show empty form without submission > return form > > but I just loss my mind after 24 ours of trying this or similar > uploads. > > Miroslav > > On Nov 19, 6:12 pm, Anthony <abas...@gmail.com> wrote: > > You can tell if the function is being called with a form submission by > > checking for request.vars: > > > > if request.vars: > > print 'this is a form submission' > > > > > > > > > > > > > > > > On Saturday, November 19, 2011 12:06:40 PM UTC-5, miroslavgojic wrote: > > > > > The error is caused when file is not selected. > > > By default on first run form is empty (file is not selected), and form > > > must wait for selecting and submitting. > > > > > How access to file before calling form? What that mean? > > > > > Miroslav > > > > > On Nov 19, 5:52 pm, Anthony <aba...@gmail.com> wrote: > > > > You might need to access the file before calling form.accepts (first > > > you'll > > > > have to check that form.vars.myfile exists). You can also access it > via > > > > request.vars.myfile (which won't change, even after form.accepts). > > > > > > Anthony > >