You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
from flask import Flask, render_template, request, json
|
|
|
|
app = Flask(__name__)
|
|
@app.route("/")
|
|
def index():
|
|
return render_template("startupterrace-form.html")
|
|
|
|
|
|
@app.route("/datas/", methods=['GET', 'POST'])
|
|
def datas():
|
|
print(request.form)
|
|
|
|
if request.method == 'POST':
|
|
filename = 'data666.json'
|
|
# 讀出 JSON
|
|
with open(filename, 'r', encoding='utf-8') as file:
|
|
json_data = json.load(file)
|
|
print(json_data)
|
|
|
|
# 整理(插入)資料
|
|
json_data.append(request.form)
|
|
print(json_data)
|
|
|
|
# 寫入 JSON
|
|
with open(filename, 'w', encoding='utf-8') as file:
|
|
# file.write("\n")
|
|
json.dump(json_data, file, ensure_ascii=False)
|
|
return render_template("yourdata.html")
|
|
|
|
|
|
@app.route("/happy/")
|
|
def happy():
|
|
print(request)
|
|
print(type(request))
|
|
return "開心"
|
|
|
|
|
|
def result():
|
|
if request.method == 'POST':
|
|
result = request.form
|
|
return render_template("result.html", result=result)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True)
|