0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

URLで送信した変数の受け取り方

Last updated at Posted at 2024-06-16
@app.route('/EmployeeSystem/<int:id>', methods=['POST'])
def register(id):
    data = request.get_json()
    name = data.get('name')
    

    data = {
        "id":id,"名前":name
    }
    
    return jsonify(data), 200

URLのint:idの部分でデータ型と変数名を決める
この時点で既にidには社員IDが格納されている

関数に対しての受け渡し

def fetch_employee(employee_id=1):
    # 関数の中でemployee_idを使う
    print(f"Fetching employee with ID: {employee_id}")

デフォルト値を使用して関数を呼び出す
fetch_employee()  # 出力: Fetching employee with ID: 1
fetch_employee(5)  # 出力: Fetching employee with ID: 5

fetch_employee(employee_id=1):で関数に渡す変数はデフォルトが1であると定義する
そしてもしfetch_employee(5)としたら
employee_id=5という情報となる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?