二手产品经理

二手产品经理

THIS IS RENO

GET - 82 days - Learn Python online for 100 days

Record#

  1. Today I learned the method for receiving variables in the request: get.
  2. The get method is passed through URL parameters, and in the code, request.args is used to access all the variables and their values passed through the URL.
  3. The receiving method still needs to be defined in the route definition: methods=['GET']
  4. There are two differences compared to post:
    1. In the route definition, one is for receiving post and the other is for receiving get.
    2. In the code, one variable is assigned to form.request and the other is assigned to request.args.
  5. Today's exercise is to pass variables through the URL and display a page in two languages.

CODE#

from flask import Flask, request
app = Flask(__name__)


@app.route('/', methods=["GET"])
def index():
    data = request.args
    if data["lang"].lower() == "en":
        return "Hello English"
    elif data["lang"].lower() == "cn":
        return "你好 中国话"


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.