I use wtforms to handle forms. so i create form like this:
class ProfileForm(Form):
firstName = TextField(_('firstName'), [validators.Required(), validators.Length(min=3, max=45)])
lastName = TextField(_('lastName'), [validators.Required(), validators.Length(min=3, max=45)])
avatar = FileField(_('avatar'), [check_file])
this form work in simple upload fine ... but what about ajax ?
is there any plugin to create iFrame or somethings to upload file via ajax? or i must handle this form in another way?
ps: IE support be important
ps2: i use wtform for another without file in ajax to. just by serialize form and submit it ...
You should try installing and using Flask-Sijax. It uses JQuery and AJAX.
http://packages.python.org/Flask-Sijax/
It also has an example on uploading via AJAX.
来源:https://stackoverflow.com/questions/14416706/upload-file-in-ajax-with-wtforms