在我的代码.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
有人知道这个问题是什么吗?
答案 0 :(得分:0)
哦,我发现了一个问题...
return redirect('/')
应该是:
redirect('/')
这可能会产生你的500问题。