在使用sijax 上传文件时 弹出错误 “you tried to perform an action in a wrong way”,请大神解答下什么原因,我只想在registeruploadcallback 时传递自己参数,当去除参数 argsextra=(2,2,) 时就正常。请问 argsextra 参数怎么传递?
def my():
form_init_js = ''
form_init_js += g.sijax.register_upload_callback(form_id ='fmAvatar',callback =AjaxAvatarUpload.file_handler,args_extra=(2,2,))
if g.sijax.is_sijax_request:
print('ajax')
#call_test_callbacks(g)
return g.sijax.process_request()
if request.method == "POST":
_email = request.form.get("email")
_gender = request.form.get("gender")
current_user.email = _email
current_user.gender = _gender
current_user.save()
return render_template("info.html",title=u"提示信息",info=(u"保存成功",),link=request.path)
return render_template("my.html",form_init_js=form_init_js)
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
class AjaxAvatarUpload(object):
"""
"""
@staticmethod
def file_handler(obj_response, files, form_values):
tipMsg =""
if 'file' not in files:
tipMsg = 'Bad upload'
file_data = files['file']
file_name = file_data.filename
if file_name is None:
tipMsg = 'Nothing uploaded'
file_type = file_data.content_type
file_size = len(file_data.read())
if file_size > current_app.config['UPLOAD_FOLDER_AVATAR']:
tipMsg = u"文件大小超过2MB"
#obj_response.html('#%s' % container_id, tipMsg)
if not AjaxAvatarUpload.allowed_file(file_data.filename):
tipMsg = u"不允许的文件类型"
#obj_response.html('#%s' % container_id, tipMsg)
filename = secure_filename(file_data.filename)
file_data.save(os.path.join(current_app.config['UPLOAD_FOLDER_AVATAR'], filename))
obj_response.html("#formTwoResponse", tipMsg)
return
@staticmethod
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS