After the next 90 minutes, ideally you should:
<html> <body> <p>This is a paragraph</p> </body> </html>
<html> <body> <p>This is a paragraph <strong>with a strong message</>.</p> </body> </html>
<html> <head> <style> strong { color: red; } </style> </head> <body> <p>This is a paragraph <strong>with a strong message</>.</p> </body> </html>
<img src="image.png" />
from flask import Flask
app = Flask('SoftwareCarpentry')
@app.route('/')
def index():
return """
<html>
<body>
<p>Hello World</>
</body>
</html>
"""
app.run()
$ python flaskr.py
from flask import Flask, request
app = Flask('SoftwareCarpentry')
@app.route('/')
def index():
name = request.args.get('name', 'World')
return """
<html>
<body>
<p>Hello {0}</>
</body>
</html>
""".format(name)
app.run()
The previous operation is common, flask supports it builtin
<html>
<body>
<p>Hello {{ name }}</p>
</body>
</html>
from flask import Flask, render_template, request
app = Flask('SoftwareCarpentry')
@app.route('/')
def index():
name = request.args.get('name', 'World')
return render_template('greet.html', name=name)
app.run()
<html>
<body>
<p>Value is {{ value }}</p>
<p><img src="pow-fig?value={{ value }}"</p>
</body>
</html>
from flask import Flask, render_template, request
import numpy as np
from matplotlib import pyplot as plt
app = Flask('SoftwareCarpentry')
@app.route('/')
def index():
value = float(request.args.get('value', 2.0))
return render_template('pow.html', value=value)
@app.route('/pow-fig'):
def pow_fig():
value = float(request.args.get('value', 2.0))
fig,ax = plt.subplots()
ax.plot(np.arange(10)**value)
ax.set_xlabel('x')
ax.set_ylabel('pow(x,{})'.format(value))
fig.savefig('tmp.png')
data = open('tmp.png', 'rb')
return data.read()
app.run()
We could do better code, but this is pretty decent
<html>
<body>
<p>Value is {{ value }}</p>
<p>
Go to <a href="/?value={{ value - 1}}">prev</a><br />
Go to <a href="/?value={{ value + 1}}">next</a>
<p><img src="pow-fig?value={{ value }}"</p>
</body>
</html>
<form action="/form" method="get">
<p>Set <input name="value" value="{{ value }}" />
<input type="submit" />
</form>
For more information, the Mozilla Developer Network is an excellent resource.