Record#
- Continue learning about Flask today.
- Use <> to pass parameters in the route,
@app.route('/<pageNumber>')
, and accept the parameter like thisdef index(pageNumber):
. - Today's exercise is to write two simple pages, use parameter passing and templates to display different content.
CODE#
from flask import Flask
app = Flask(__name__)
@app.route('/<days>')
def index(days):
if days == '78':
text = "This is the diary for 78"
elif days == '79':
text = "This is the diary for 79"
f = open("template/blog.html", "r")
page = f.read()
f.close()
page = page.replace("{days}", days)
page = page.replace("{text}", text)
return page
app.run(host='0.0.0.0', port=81)