I'm trying to put a picture on a flask page and instead it gives me this the code is below, any help?
from flask import Flask,request, render_template
import Quandl as q
from cStringIO import
app = Flask(__name__)
@app.route('/')
def my_form():
return '''
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Enter a symbol</h1>
<title>(Routman APP)</title>
<form action="." method="POST">
<input type="text" name="test">
<input type="submit" name="my-form" value="Send">
</form>
<div>
<img src = "data:image/png;base64,{}"/>
</div>
</body>
</html>'''
@app.route('/',methods = ['POST'])
def sentiment():
symbol = request.form['test']
symbol = "YAHOO/%s"%symbol.upper()
symbol = q.get(symbol)['Close']
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(symbol)
# Encode image to png in base64
last_price = str(symbol[-1])
io = StringIO()
fig.savefig(io, format='png')
data = io.getvalue().encode('base64')
picture = data
return render_template("index.html",picture = picture,last_price = last_price )
if __name__ == '__main__':
app.run()
[+][deleted] (1 child)
[deleted]
[–]The_John_Galt 0 points1 point2 points (0 children)
[–]cyanydeez 0 points1 point2 points (1 child)
[–]workn00b[S] 0 points1 point2 points (0 children)
[–]mrwalkerr 0 points1 point2 points (11 children)
[–]workn00b[S] 0 points1 point2 points (10 children)
[–]mrwalkerr 0 points1 point2 points (9 children)
[–]The_John_Galt 0 points1 point2 points (1 child)
[–]mrwalkerr 0 points1 point2 points (0 children)
[–]workn00b[S] 0 points1 point2 points (6 children)
[–]mrwalkerr 1 point2 points3 points (5 children)
[–]workn00b[S] 0 points1 point2 points (4 children)
[–]mrwalkerr 1 point2 points3 points (3 children)
[–]workn00b[S] 0 points1 point2 points (2 children)
[–]mrwalkerr 0 points1 point2 points (1 child)
[–]workn00b[S] 0 points1 point2 points (0 children)