from flask import render_template, request
from testapp import app


@app.route("/form", methods=["GET", "POST"])
def index():
    if request.method == "GET":
        return render_template("testapp/index.html")
    if request.method == "POST":
        # POSTデータを受け取る
        data = request.get_data(as_text=True)  # バイナリデータではなくテキストとして取得する

        # 受け取ったデータを印刷する
        print("Received data:", data)

        # 必要な処理を行う（例：データベースへの書き込みなど）
        return "Data received successfully"

        # print("POSTデータ受け取ったので処理します。")
        # data = request.form["text"]
        # print(data)
        # return render_template("testapp/index.html")


# @app.route("/test")
# def index2():
#     my_dict = {
#         "insert_something1": "views.pyのinsert_something1部分です。",
#         "insert_something2": "views.pyのinsert_something2部分です。",
#     }
#     return render_template("testapp/index.html", my_dict=my_dict)
