图片显示不正确

时间:2021-04-12 15:05:31

标签: python html image web

我正在尝试展示用户通过网站上传的图片。 但是当我尝试在屏幕上显示它时,它显示了很久以前加载的图像(现在它根本不存在)。例如,这是我文件中的图片,我想显示它。enter image description here,但程序返回另一个文件。

@app.route('/sample_file_upload', methods=['POST', 'GET'])
def sample_file_upload():
if request.method == 'POST':
    f = request.files['file']

    try:
        f = f.read()
        with open('text.txt', 'wb') as text:
            text.write(f)
        with open('text.txt', 'rb') as textfile:
            bytestring = textfile.read()
            with open('static/face.png', 'wb') as imagefile:
                imagefile.write(bytestring)

        return redirect(url_for('create'))
    except ValueError:
        pass
return render_template('face.html')

(f 返回字节字符串) 在该程序在 html 代码上返回 pic 之后 return render_template('index.html', pic='static/face.png') 但它不工作。请帮助)

0 个答案:

没有答案