()
return jsonify(res)
图片上传处理
图片上传处理
图片上传处理
def upload():
    """图片上传处理"""
    file=request.files.get('editormd-image-file')
    if not file:
        res={
            'success':0,
            'message':'图片格式异常'
        }
    else:
        ex=os.path.splitext(file.filename)[1]
        filename=datetime.now().strftime('%Y%m%d%H%M%S')+ex
        file.save(os.path.join(current_app.config['IMAGES_FOLDER'],filename))
        #返回
        res={
            'success':1,
            'message':u'图片上传成功',
            'url':url_for('.static',filename='pictures/{}'.format(filename))
        }
    return jsonify(res)
def upload ( ) : file = request . files . get ( 'editormd-image-file' ) if not file : res = { 'success' : 0 , 'message' : '图片格式异常' } else : ex = os . path . splitext ( file . filename ) [ 1 ] filename = datetime . now ( ) . strftime ( '%Y%m%d%H%M%S' ) + ex file . save ( os . path . join ( current_app . config [ 'IMAGES_FOLDER' ] , filename ) ) #返回 res = { 'success' : 1 , 'message' : u'图片上传成功', 'url' : url_for ( '.static' , filename = 'pictures/{}' . format ( filename ) ) } return jsonify ( res )