二手产品经理

二手产品经理

THIS IS RENO

flask - 78 days - Learn Python online for 100 days

Record#

  1. Continue learning about Flask today.
  2. Use <> to pass parameters in the route, @app.route('/<pageNumber>'), and accept the parameter like this def index(pageNumber):.
  3. 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)

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.