【发布时间】:2018-03-27 02:05:55
【问题描述】:
在我的代码.tpl 文件中:
<form method='post' action='/upload' enctype='multipart/form-data'>
<input type='file' name='newfile'>
<input type='submit' value='Submit'>
</form>
我的控制器代码是:
@app.post('/upload')
def upload():
newfile = request.files.get('newfile')
save_path = os.path.join(config.UPLOAD_DIRECTORY, newfile.filename)
newfile.save(save_path)
return redirect('/')
浏览并提交后,出现以下500错误。
Internal Server Error
例外:AttributeError('save',)
追溯:
Traceback (most recent call last):
File "/var/www/myproject/bottle.py", line 768, in _handle
return route.call(**args)
File "/var/www/myproject/bottle.py", line 1518, in wrapper
rv = callback(*a, **ka)
File "/var/www/myproject/controllers/index.py", line 753, in upload
newfile.save(save_path)
File "/usr/lib/python2.7/cgi.py", line 521, in __getattr__
raise AttributeError, name
AttributeError: save
有人知道这是什么问题吗?
【问题讨论】:
-
你能指定你使用的WSGI服务器吗?我在保存文件时发现了一些问题。我发现cherrypy最适合使用bottle,或者如果你想要异步,可以使用gevent.pywsgi。
-
我正在使用cherrypy。但是,问题还是一样的。 UPLOAD_DIRECTORY = 'var/www/myproject/images/' 我设置了该文件夹的所有权限。
-
你使用的是哪个版本的 Bottle/
标签: python file-upload bottle