I want to render the template but flask is not rendering it . Since I have to pass the path of the image to the HTML file , it is displaying the path on the terminal but when I want to send the path by rendering it , it is not sending the path . Image source becomes unknown.
if __name__ == "__main__":
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
@app.route('/input', methods=['GET','POST'])
def result():
if request.method == 'POST':
file = request.files['file']
basepath = os.path.dirname(__file__)
print(file.filename)
input_p = file.save(os.path.join(basepath,'uploadsinput',secure_filename(file.filename)))
#output_p = file.save(os.path.join(basepath,'uploadsoutput',secure_filename(file.filename)))
cli((os.path.join(basepath,'uploadsinput',secure_filename(file.filename))),
(os.path.join(basepath,'uploadsoutput',secure_filename(file.filename))) )
userImage=os.path.join(basepath,'uploadsoutput',secure_filename(file.filename))
return render_template('index.html',message=userImage)
The last line is not rendering the template . I don't know that whether I am passing get request (image path) in Post request or from return statement because it gives 500 Internal Server Error
<div class="row py-4">
<div class="col-lg-6 mx-auto">
<!-- Upload image input-->
<div class="input-group mb-3 px-2 py-2 rounded-pill bg-white shadow-sm">
<form id="upload-file" method="post" enctype="multipart/form-data">
<fieldset>
<label id="upload-label" for="file" class="font-weight-light text-muted">Choose file
</label>
<input id="upload" type="file" onchange="readURL(this);" class="form-control border-0" name="file">
</fieldset>
</form>
</div>
<p class="font-italic text-white text-center">The image uploaded will be rendered inside the box below.</p>
<div class="image-area mt-4">
<img id="imageResult" src="#" alt="" class="img-fluid rounded shadow-sm mx-auto d-block">
</div>
<button type="button" class="btn btn-primary btn-med" id="btn-predict" style="margin-left: 33%; margin-top: 2%">Convert!</button>
<div class="image-area mt-7.5" style="margin-top: 10%">
<img src="{{message}}" class="img-fluid rounded shadow-sm mx-auto d-block">
</div>
<a href="/return-files/{{value}}" target="blank"><button class='btn btn-primary'>Download</button></a>
</div>
</div>
</div>
</body>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…