so I am new to HTML. I am building a web app with flask. I am trying to visualise some HTML markup, but it doen't show up properly.
I have the following flask route:
@app.route('/predict',methods=['GET','POST'])
def api():
if request.method == "POST":
input_data = request.form['rawtext']
output_data = model_api(input_data)
alignedText = output_data["words"]
predictions = output_data["predictions"]
#response = jsonify(output_data)
print(predictions, flush=True)
if request.values.get('type') == 'image':
text = output_data["text"]
ents = turnIntoSpacyFormat((predictions))
inp = {"text": text, "ents": ents, "title": None}
htmlm = displacy.render(inp, style="ent", manual=True)
return render_template('index.html', text=alignedText, predictions=predictions, htmlm=htmlm)
else:
return render_template('index.html', text=alignedText, predictions=predictions)
else:
return render_template('index.html')
The function displacy.render returns the html markup. I am passing it to index.html. The part where I am trying to print it looks the following (last few lines):
<!-- Result Display-->
<section class="section section-solutions-about grey darken-2">
<div class="container white-text">
<!-- Icon Section -->
<div class="row">
<div class="col s12 m6">
<div class="icon-block">
<!--<h5 class="center">Your Text</h5>-->
<p>Text: <span style="color:#0091EA;">{{ text }} </span></p>
<!--<p class="light">{{ctext}}</p>-->
<div class="alert alert-info" role="alert"><p>Entities: <span style="color:#0091EA;">{{ predictions }} </span></p><br/>
</div>
</div>
</div>
</div>
<div class="entities" style="line-height: 2.5; direction: ltr"> Doesn't show up correctly</div>
{{ htmlm }}
</div>
</section>
I was thinking i could make it show up on the html page with that: {{ htmlm }}
Apparently that prints a string representation of the markup though. First i thought that maybe the markup was faulty. But when I enter the exact same on in the html file like one line above the {{ htmlm }} command it shows up as desired.
Here is what is printed:
The first line is what is desired and shows up by pasting the html markup into the html file. The second output is what I am getting through accessing the htmlm variable.
Does anybody know how to do this?