upload file in ajax with wtforms

 ̄綄美尐妖づ 提交于 2019-12-08 02:25:30

问题


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 ...


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!