Hi all,
Using web.py 0.3, I would like to get the content of a submitted file.
Below is the code I use, I can just create the file, as the 'value' attribute
brings the filename.
But what brings the content? I need it to be the argument of write()
Thank you for your help.
import web
urls = ('/', 'register','/index','index')
app = web.application(urls, globals())
render = web.template.render('templates/')
vpass = form.regexp(r".{3,20}", 'must be between 3 and 20 characters')
vemail = form.regexp(r"....@.*", "must be a valid email address")
register_form = form.Form(
form.Textbox("username", description="Username"),
form.Textbox("email", vemail, description="E-Mail"),
form.Password("password", vpass, description="Password"),
form.Password("password2", description="Repeat password"),
form.Checkbox("check"),
form.Radio("r1",['a' , 'b' , 'd']),
form.Radio("r2",['d','e','f']),
form.File('fichier'),
form.Button("submit", type="submit", description="Register"),
validators = [
form.Validator("Passwords did't match", lambda i: i.password ==
i.password2)]
)
class register:
def GET(self):
my_form = register_form()
return render.register(my_form,'v1','v1','v1','v1','v1')
def POST(self):
my_form = register_form()
if not my_form.validates():
return render.register(my_form,'v1','v1','v1','v1','v1')
else:
u =my_form['username'].value
e =my_form['email'].value
c =my_form['check'].value
r1=my_form['r1'].value
r2=my_form['r2'].value
x = my_form['fichier']
fichier = open( 'upload/'+ x.value ,"wb")
# fichier.write(???????)
fichier.close()
return render.register(my_form,'v1','v1','v1','v1','v1')
if __name__ == "__main__":
app.run()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---