简体   繁体   English

使用Bottle的图片上传错误

[英]Image upload error using Bottle

In my code .tpl file: 在我的代码.tpl文件中:

<form method='post' action='/upload' enctype='multipart/form-data'>
   <input type='file' name='newfile'>
   <input type='submit' value='Submit'>
</form>

My controller code is: 我的控制器代码是:

@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('/')

After browse and submit, I got following 500 error. 浏览并提交后,出现以下500错误。

Internal Server Error

Exception: AttributeError('save',) 异常: AttributeError('save',)

Traceback: 追溯:

 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

Could someone know what this issue is? 有人知道这个问题是什么吗?

Oh I see a problem... 哦,我看到一个问题...

return redirect('/')

Should be: 应该:

redirect('/')

That could what is generating your 500 issue. 那可能是引起您500问题的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM