from flask import render_template, request
from testapp import app
data = []
@app.route("/form", methods=["GET", "POST"])
def index():
if request.method == "GET":
return render_template("testapp/index.html")
if request.method == "POST":
# POSTデータを受け取る
data.append(
request.get_data(as_text=True)
) # バイナリデータではなくテキストとして取得する
# 受け取ったデータを印刷する
print("Received data:", data)
if len(data) > 10:
data.clear()
# 必要な処理を行う(例:データベースへの書き込みなど)
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)