【发布时间】:2021-04-14 10:17:20
【问题描述】:
您好,我编写了一个博客脚本,但收到 FileNotFound 错误。 Python代码:
@app.route('/upload',methods=['POST'])
def upload():
title = request.form['title']
context = request.form['text']
author = request.form['author']
img=request.files['img']
path = os.path.join(app.root_path,'/images',img.filename)
img.save(path)
new=Posts(title=title,context=context,image=path,author=author)
db.session.add(new)
db.session.commit()
return redirect(url_for('blog'))
错误:
img.save(path)
File "/home/coderrpy/.virtualenvs/python/lib/python3.8/site-packages/werkzeug/datastructures.py", line 3066, in save
dst = open(dst, "wb")
FileNotFoundError: [Errno 2] No such file or directory: '/images/images.jpeg'
我以前从来没有收到过这样的错误,我不知道为什么。
请帮帮我
【问题讨论】:
-
从
/images中删除/,只保留images
标签: python python-3.x flask