def post__upload(user): try: from form import FileForm form = FileForm() assert form.validate_on_submit(), 'invalid form fields' data = form.file.data File.upload_file(user, data) flash('上传成功!') except AssertionError as e: message = e.args[0] if len(e.args) else str(e) flash('上传失败!'+message) return redirect('/file')
def upload(): if request.method == 'GET': return render_template('home_upload.html') else: try: user = current_user f = request.files.get('file') File.upload_file(user, f) flash('上传成功!') except AssertionError as e: message = e.args[0] if len(e.args) else str(e) return message, 400 return redirect('/home')