赞
踩
# 上传文件 @route('/upload', method=['POST','GET']) def upload(): f = request.files.get('file') if f == '': return '文件不能为空' # 名字, 格式 name, ext = os.path.splitext(f.raw_filename) if ext not in ('.png', '.jpg', '.jpeg'): return 'File extension not allowed.' # 保存文件 f.save('static/file/' + name + ext)
注:
f.raw_filename
:支持文件名为中文
f.filename
:不支持
当文件名重复时,会报错文件重复
@route('<filename:re:.*\.css|.*\.js|.*\.png|.*\.jpg|.*\.jpeg|.*\.gif|.*\.otf|.*\.eot|.*\.woff|.*\.mp3|.*\.map|.*\.mp4|.*\.json|.*\.mtn|.*\.svg|.*\.ttf|.*\.woff2.*\.swf>')
def server_static(filename):
"""定义static下所有的静态资源路径"""
return static_file(filename, root='static/file/')
更多文章:有勇气的牛排—python
官方地址:https://www.920vip.net/
官方QQ群交流: 779133600
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。