二手产品经理

二手产品经理

THIS IS RENO

request - 81 days - Learn Python online for 100 days

Record#

  1. Today's exercise is similar to yesterday's exercise. I still need to write a page to validate the posted data and return information based on the validation result.
  2. For me, today's exercise has improved my understanding of Flask a little bit, and reminded me of HTML syntax a little bit.

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)

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