如何显示以下图像?

how to display the following images?

首先,我在 app.py 文件中定义了两个函数,如下所示:

senti=["furious","angry","angry0","Indiferent","happy","enthusiastic","Euphoric"]

def predict(text):
    seqs = tok.texts_to_sequences([text])
    print(text)
    word_index = tok.word_index
    print('Found %s unique tokens.' % len(word_index))
    sequence_pred = sequence.pad_sequences(seqs, maxlen=MAX_SEQUENCE_LENGTH)
    print(sequence_pred)
    prediction = model.predict(sequence_pred)
    print(prediction)
    return senti[np.argmax(prediction[0])]

在这里,我得到了 image_url 的值,即我的图像路径,如下所示:

@app.route("/", methods=['GET', 'POST'])
def index():
    senti=["furious","angry","angry0","Indiferent","happy","enthusiastic","Euphoric"]
    images=['static/angry.jpg','static/angry.jpg','static/angry.jpg','static/smile.jpg','static/smile.jpg','static/smile.jpg','static/smile.jpg']
    lookup_keys = dict(zip(senti, images))
    print(request.method)
    if request.method == 'POST':
        q=request.form['querytext']
        prediction=predict(q)
        image_path = lookup_keys[prediction] # get the path
        print(image_path)
        return render_template("result.html",
                               prediction=prediction,
                               text=q,
                               image_url=image_path)
    return render_template("main.html")

然后根据我想要显示的结果和图像,我只使用静态文件夹中包含的两个 smile.jpg 和 angry.jpg, 之后我将我的模板渲染为:"result.html"

此文件包含以下标签,显示文本和预测如下:

<h3>{{text}} </br> <button class="button-primary">{{prediction}}</button></h3>

到目前为止一切正常我想动态显示我试过的图像:

<h3>{{image_url}}<td><img src={image_url} alt=""></td></h3>

但是没有显示任何内容,如果我放置以下标签:

<td><img src='static/angry.jpg' alt=""></td>

图像显示有任何问题我想感谢支持修改上面的标签以动态显示图像我的意思是这部分:

 <td><img src='static/angry.jpg' alt=""></td>

我想用我的变量 image_url 的值动态地更改这个字符串 'static/angry.jpg',我是一个使用 flask 的初学者,所以我不知道如何使用这个值,谢谢支持。

如果您确定您的 image_url 路径没问题,那么:

<td><img src="{{image_url}}" alt=""></td>