jinja2.exceptions.UndefinedError: ‘predictions’ is undefined

Solution
            else:
            return render_template('home.html' , error = error)
    @app.route('/predict' , methods = ['GET' , 'POST'])
    def success():
    predictions = dict() # if predictions is not empty ok, else doens't matter
    error = ''
    target_img = os.path.join(os.getcwd() , 'static/images')
    if request.method == 'POST':
        if (request.files):
            file = request.files['file']
            if file and allowed_file(file.filename):
                file.save(os.path.join(target_img , file.filename))
                img_path = os.path.join(target_img , file.filename)
                img = file.filename

            class_result , prob_result = predict(img_path , model)

            predictions = {
                  "class1":class_result[0],
                    "class2":class_result[1],
                    "class3":class_result[2],
                    "prob1": prob_result[0],
                    "prob2": prob_result[1],
                    "prob3": prob_result[2],
            }

        else:
            error = "Please upload images of jpg , jpeg and png extension only"

        if(len(error) == 0):
            return  render_template('predict.html' , img  = img , predictions = predictions)
        else:
            return render_template('home.html' , error = error, predictions = predictions)

else:
    return render_template('home.html', predictions = predictions)
{% if predictions|length > 0 %}

 
            Class
            Probability
        
        
          {{predictions.class1}}
            {{predictions.prob1}}
        
        
          {{predictions.class2}}
            {{predictions.prob2}}
        
        
          {{predictions.class3}}
            {{predictions.prob3}}

{% endif %}