bottle库上传文件
安装bottle库
pip install bottle
上传代码
import bottle
@bottle.get('/upload')
def upload_get():
return bottle.static_file('index.html', 'd:/web')
@bottle.post('/upload')
def upload_post():
filename = bottle.request.forms.get('filename')
data = bottle.request.files.get('file')
data.save('d:/web/' + filename, overwrite=True)
bottle.run(host='127.0.0.1', port=80)
静态文件index.html
<html>
<head>
<title>文件上传</title>
</head>
<body>
<div>
<form action"/upload" method="post" enctype="multipart/form-data">
文件名: <input type="text" name="filename"><br/>
文件: <input type="file" name="file"><br/>
<input type="submit" value="上传" />
</form>
<div>
</body>
</html>
posted on 2022-09-25 09:11 1226032602 阅读(66) 评论(0) 收藏 举报