第一次学flask,在尝试flask文档中的上传文件时出现报错
Could not build url for endpoint 'uploaded_file' with values ['filename']. Did you mean 'upload_file' instead?
文档代码
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',
filename=filename))
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
'''
最后发现是url_for函数要求参数内的函数名和route下的函数名不一样。。
文档也会出错的吗。。
本文记录了一位初学者在使用Flask框架进行文件上传功能开发时遇到的问题及解决过程。在尝试按照官方文档操作时,遇到了url_for函数的命名不匹配错误,最终通过调整函数名与url_for参数保持一致解决了问题。
8047

被折叠的 条评论
为什么被折叠?



