二手产品经理

二手产品经理

THIS IS RENO

request - 81天 - 在线学python100天

记录#

  1. 今天的练习与昨天练习差不多,还是写一个页面 post 数据做验证,根据验证结果返回信息。
  2. 对我来说今天的练习让我对 flask 的掌握又进步了一点点,对 html 语法又回忆起来一点点。

CODE#

from flask import Flask, request

app = Flask(__name__)


@app.route("/")
def index():
    page = """
    <form action="/v" method="post">
    <p>Are you made of metal? <input type="radio" name="metal" value="yes">yes <input type="radio" name="metal" value="no">no</p>
    <p>What is infinity +1 ? <input name="vnum" type="text"></p>
    <p>Which is your favorite food? <select name="food">
      <option value="humanfood">Human food</option>
      <option value="apple">Apple</option>
    </select></p>
    <p>
    <p></p>
    <button name="button" value="button">Button</button>
  """
    return page


@app.route("/v", methods=["POST"])
def process():
    form = request.form
    metal = "no"
    vnum = "verybig"
    food = "apple"
    vnum1 = form["vnum"].lower()
    food1 = form["food"].lower()
    if form["metal"] == metal and vnum1 == vnum and food1 == food:
        page = """
        You are hummer!
        """
    else:
        page = """
        You are Robot!
        """

    return page


app.run(host='0.0.0.0', port=81)

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。